油猴脚本:优化控制台日志打印。
parent
80e8024faf
commit
6e6be5e5a1
|
@ -472,5 +472,4 @@
|
||||||
window.dispatchEvent(new Event('urlchange'))
|
window.dispatchEvent(new Event('urlchange'))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log('ds_github loaded')
|
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -6,4 +6,4 @@ window.__ds_global__={
|
||||||
GM_setValue: () => {},
|
GM_setValue: () => {},
|
||||||
GM_notification: () => {}
|
GM_notification: () => {}
|
||||||
}
|
}
|
||||||
console.log('ds_global loaded')
|
console.log("ds_global completed")
|
|
@ -3,20 +3,24 @@ const path = require('path')
|
||||||
const log = require('../../utils/util.log')
|
const log = require('../../utils/util.log')
|
||||||
let scripts
|
let scripts
|
||||||
|
|
||||||
function buildScript (sc, content) {
|
function buildScript (sc, content, scriptName) {
|
||||||
const grant = sc.grant
|
let grantStr = ''
|
||||||
const pre = 'window.addEventListener("load",' +
|
for (const item of sc.grant) {
|
||||||
' ()=> { \r\n'
|
if (grantStr.length > 0) {
|
||||||
let grantSc = ''
|
grantStr += '\r\n'
|
||||||
for (const item of grant) {
|
}
|
||||||
grantSc += (item.indexOf('.') > 0 ? '' : 'const ') + item + ' = window.__ds_global__[\'' + item + '\']\r\n'
|
grantStr += (item.indexOf('.') > 0 ? '' : 'const ') + item + ' = window.__ds_global__[\'' + item + '\']'
|
||||||
}
|
}
|
||||||
const tail = ';' + content + '\r\n' +
|
|
||||||
'})'
|
return 'window.addEventListener("load", ()=> {\r\n' +
|
||||||
return pre + grantSc + tail
|
grantStr + ';\r\n' +
|
||||||
|
content +
|
||||||
|
(scriptName ? `\r\nconsole.log("ds_${scriptName} completed")` : '') +
|
||||||
|
'\r\n})' +
|
||||||
|
(scriptName ? `\r\nconsole.log("ds_${scriptName} loaded")` : '')
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadScript (content) {
|
function loadScript (content, scriptName) {
|
||||||
// @grant GM_registerMenuCommand
|
// @grant GM_registerMenuCommand
|
||||||
// @grant GM_unregisterMenuCommand
|
// @grant GM_unregisterMenuCommand
|
||||||
// @grant GM_openInTab
|
// @grant GM_openInTab
|
||||||
|
@ -51,7 +55,7 @@ function loadScript (content) {
|
||||||
}
|
}
|
||||||
const script = arr[start + 1].trim()
|
const script = arr[start + 1].trim()
|
||||||
|
|
||||||
sc.script = buildScript(sc, script)
|
sc.script = buildScript(sc, script, scriptName)
|
||||||
return sc
|
return sc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,8 +75,8 @@ const api = {
|
||||||
},
|
},
|
||||||
load (rootDir) {
|
load (rootDir) {
|
||||||
scripts = {}
|
scripts = {}
|
||||||
scripts.github = loadScript(readFile(rootDir, 'github.script'))
|
scripts.github = loadScript(readFile(rootDir, 'github.script'), 'github')
|
||||||
scripts.google = loadScript(readFile(rootDir, 'google.js'))
|
scripts.google = loadScript(readFile(rootDir, 'google.js'), 'google')
|
||||||
// scripts.jquery = { script: readFile(rootDir, 'jquery.min.js') }
|
// scripts.jquery = { script: readFile(rootDir, 'jquery.min.js') }
|
||||||
scripts.global = { script: readFile(rootDir, 'global.script') }
|
scripts.global = { script: readFile(rootDir, 'global.script') }
|
||||||
return scripts
|
return scripts
|
||||||
|
|
Loading…
Reference in New Issue