MCPcopy Index your code
hub / github.com/Tampermonkey/tampermonkey / addNewUserScript

Function addNewUserScript

src/background.js:2925–3195  ·  view source on GitHub ↗
(o)

Source from the content-addressed store, hash-verified

2923};
2924
2925var addNewUserScript = function(o) {
2926 // { tabid: tabid, force_url: durl, url: url, src: src, ask: ask, defaultscript:defaultscript, noreinstall : noreinstall, save : save, sync: sync, cb : cb }
2927 var reset = false;
2928 var allowSilent = false;
2929 var hashChanged = false;
2930
2931 if (o.name == undefined) o.name = null;
2932 if (o.clean == undefined) o.clean = false;
2933 if (o.defaultscript == undefined) o.defaultscript = false;
2934 if (o.ask == undefined) o.ask = true;
2935 if (o.url == undefined || o.url == null) o.url = "";
2936 if (o.save == undefined) o.save = false;
2937 if (o.hash == undefined) o.hash = "";
2938 if (o.force_url == "") o.force_url = null;
2939
2940 var script = scriptParser.createScriptFromSrc(o.src);
2941
2942 if (o.name && o.name != script.name) {
2943 console.log("bg: addNewUserScript() Names do not match!");
2944 return false;
2945 }
2946
2947 if (!script.name || script.name == '' || (script.version == undefined)) {
2948 chrome.tabs.sendMessage(o.tabid,
2949 { method: "showMsg", msg: I18N.getMessage('Invalid_UserScript__Sry_')},
2950 function(response) {});
2951 return false;
2952 }
2953
2954 var oldscript = TM_storage.getValue(script.name, null);
2955 var msg = '';
2956
2957 if (!o.clean && oldscript && oldscript.system && !o.defaultscript) return false;
2958
2959 if (script.options.compat_uW_gmonkey) {
2960 chrome.tabs.sendMessage(o.tabid,
2961 { method: "showMsg", msg: I18N.getMessage('This_script_uses_uW_gm_api_')},
2962 function(response) {});
2963
2964 return false;
2965 }
2966
2967 if (oldscript) {
2968 hashChanged = (o.hash && oldscript.hash != o.hash);
2969 }
2970
2971 script.hash = o.hash ? o.hash : (oldscript ? oldscript.hash : null);
2972 script.lastUpdated = (new Date()).getTime();
2973 script.system = o.defaultscript;
2974 script.fileURL = o.url;
2975
2976 if (!o.clean && o.force_url) {
2977 /* Note: Replace downloadURL with the users preference and clear the updateURL.
2978 When a new script version is detected it will be installed and the parameters
2979 (@downloadURL, @updateURL) of the script will be used again. */
2980 script.updateURL = null;
2981 script.downloadURL = o.force_url;
2982 }

Callers 6

timeFunction · 0.85
ConfigObjectFunction · 0.85
instFunction · 0.85
gotIdFunction · 0.85
background.jsFile · 0.85
sereFunction · 0.85

Calls 5

versionCmpFunction · 0.85
mergeCludesFunction · 0.85
determineMetaURLFunction · 0.85
doitFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…