Discussions » Creation Requests

Is there any way to fix a script path before it is loaded in DOM?

§
Posted: 22 Agustus 2016

Is there any way to fix a script path before it is loaded in DOM?

There's a requireJS script using the following syntax:



RequireJS loads other script(s) from the entry point in data-main. However, the path value of data-main is broken.

I'd like to change "scripts/main" to "get?url=http://example.com/scripts/main&p=1" and therefore have it, when require.js executes, load from that path instead. Is this even possible with Greasemonkey?

§
Posted: 22 Agustus 2016
Edited: 22 Agustus 2016

Apologies. The syntax is:

§
Posted: 07 November 2016
Edited: 07 November 2016

Using greasemonkey's @run-at metadata block you can have your userscript run before any scripts or images are loaded.

Developer notes: https://wiki.greasespot.net/Metadata_Block#.40run-at

Example script:

// ==UserScript==
// @name Change Script Path
// @namespace http://tampermonkey.net/
// @version 0.1
// @description none
// @author none
// @match http*://example.org/*
// @grant none

// @run-at document-start
// @noframes
// ==/UserScript==

(function() {
'use strict';

var scripts = document.getElementsByTagName("script");
for (var n = 0; n < scripts.length; n++) {
if (scripts[n].dataMain == "scripts/main") {
scripts[n].dataMain = "get?url=http://example.com/scripts/main&p=1";
}
}
})();

Post reply

Sign in to post a reply.