forked from magicoflolis/Userscript-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserscript.js
More file actions
161 lines (157 loc) · 7.02 KB
/
Copy pathuserscript.js
File metadata and controls
161 lines (157 loc) · 7.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* eslint-env node */
import { readFileSync, writeFile } from 'fs';
import watch from 'node-watch';
const log = (...msg) => console.log(`[NodeJS] DBG ${[...msg]} ${performance.now()}ms`),
delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)),
nano = (template, data) => {
return template.replace(/\{([\w\.]*)\}/g, (str, key) => {
let keys = key.split('.'),
v = data[keys.shift()];
for(let i in keys.length) v = v[keys[i]];
return typeof v !== 'undefined' && v !== null ? v : '';
});
},
p = {
dev: './dist/magic-userjs.dev.user.js',
pub: './dist/magic-userjs.user.js',
},
js_env = process.env.JS_ENV === 'development',
jsonData = JSON.parse(readFileSync('./package.json', 'utf-8')),
buildUserJS = (evt, name) => {
let header = readFileSync('./src/header.js').toString(),
main_css = readFileSync('../tests/compiled/muserjs.css').toString(),
code = readFileSync('./src/main.js').toString(),
renderOut = (outFile, jshead) => {
let ujs = nano(header, {
jshead: jshead,
main_css: main_css,
code: code,
});
writeFile(outFile, ujs, (e) => {
return (e) ? log(e) : log(`Build-path: ${outFile}`);
});
},
time = +new Date(),
langND = `// @name ${js_env ? `[Dev] ${jsonData.userJS.name}` : jsonData.userJS.name}
// @name:zh Magic Userscript+ : 显示当前网站所有可用的UserJS脚本 Jaeger
// @name:zh-CN Magic Userscript+ : 显示当前网站所有可用的UserJS脚本 Jaeger
// @name:zh-TW Magic Userscript+ : 顯示當前網站所有可用的UserJS腳本 Jaeger
// @name:ja Magic Userscript+ : 現在のサイトの利用可能なすべてのUserJSスクリプトを表示するJaeger
// @name:ru-RU Magic Userscript+ : Показать пользовательские скрипты (UserJS) для сайта. Jaeger
// @name:ru Magic Userscript+ : Показать пользовательские скрипты (UserJS) для сайта. Jaeger
// @description ${jsonData.description}
// @description:zh 显示当前网站的所有可用UserJS(Tampermonkey)脚本,交流QQ群:104267383
// @description:zh-CN 显示当前网站的所有可用UserJS(Tampermonkey)脚本,交流QQ群:104267383
// @description:zh-TW 顯示當前網站的所有可用UserJS(Tampermonkey)腳本,交流QQ群:104267383
// @description:ja 現在のサイトで利用可能なすべてのUserJS(Tampermonkey)スクリプトを表示します。
// @description:ru-RU Показывает пользовательские скрипты (UserJS) для сайта. Легкий способ установить пользовательские скрипты для Tampermonkey.
// @description:ru Показывает пользовательские скрипты (UserJS) для сайта. Легкий способ установить пользовательские скрипты для Tampermonkey.`,
buildScript = `// ==UserScript==
${langND}
// @author ${jsonData.author}
// @version ${js_env ? time : jsonData.version}
// @icon ${jsonData.userJS.icon}
// @downloadURL ${jsonData.userJS.url}
// @updateURL ${jsonData.userJS.url}
// @supportURL ${jsonData.userJS.bugs}
// @namespace ${jsonData.userJS.homepage}
// @homepageURL ${jsonData.userJS.homepage}
// @license ${jsonData.license}
// @connect greasyfork.org
// @connect sleazyfork.org
// @connect github.com
// @connect openuserjs.org
// @match https://*/*
// @grant GM_xmlhttpRequest
// @grant GM_openInTab
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_info
// @compatible chrome
// @compatible firefox
// @compatible edge
// @compatible opera
// @compatible safari
// @noframes
// @run-at document-end
// ==/UserScript==`;
if(js_env) {
// Development version
renderOut(p.dev, buildScript);
} else {
// Release version
renderOut(p.pub, buildScript);
}
},
watcher = watch(['./src/'], { delay: 2000, filter: /\.js$/ });
log(`ENV: ${process.env.JS_ENV}`);
watcher.on('change', buildUserJS);
watcher.on('error', (e) => {
log('ERROR',e);
watcher.close();
delay(5000).then(() => {buildUserJS()});
});
watcher.on('ready', buildUserJS);
// @exclude /^https:\/\/([^/]*\.)?(\d|pay|bank|money|localhost|authorize|checkout|bill|wallet|router)[0-9]*\./
// @exclude /^https:\/\/([^/]*\.)?[\S]*\.(gov|org|cart|checkout|login|join|signin|signup|sign-up|password|reset|password_reset)$/
// @exclude *://paypal.com/*
// @exclude *://*.alipay.com/*
// @exclude *://*bank.*/*
// @exclude *://*perfectmoney.*/*
// @exclude *://*stripe.com/*
// @exclude *://*ica.yandex.com/*
// @exclude *://*authorize.net/*
// @exclude *://*2checkout.com/*
// @exclude *://192.168*
// @exclude *://127.0.0*
// @exclude *://router.*.*/*
// @exclude *://10.0.0*
// @exclude *://*skrill.com/*
// @exclude *://*zalo.me/*
// @exclude *://pay.amazon.*/*
// @exclude *://*.opayo.co.uk/*
// @exclude *://*.payza.org/*
// @exclude *://*.bluesnap.com/*
// @exclude *://securionpay.com/*
// @exclude *://*.unionpayintl.*/*
// @exclude *://*.99bill.com/*
// @exclude *://*.yeepay.com/*
// @exclude *://*payoneer.com/*
// @exclude *://*myetherwallet.com/*
// @exclude *://bitpay.com/*
// @exclude *://*.*/login
// @exclude *://*.*/join
// @exclude *://*.*/signin
// @exclude *://*.*/signup
// @exclude *://*.*/sign-up
// @exclude *://*.*/cart
// @exclude *://*.*.gov/*
// @exclude *://*.*/password_reset
// @exclude *://*.*/checkout*
// @exclude *://*.*/settings/*
// @exclude *://*.*/options/*
// @exclude *://*.*.*/login
// @exclude *://*.*.*/join
// @exclude *://*.*.*/signin
// @exclude *://*.*.*/signup
// @exclude *://*.*.*/sign-up
// @exclude *://*.*.*/cart
// @exclude *://*.*.*/checkout*
// @exclude *://*.*.*/settings/*
// @exclude *://*.*.*/options/*
// @exclude *://*.*.*.gov/*
// @exclude *://*.*.*/password_reset
// @grant GM_getResourceText
// @grant GM.getResourceText
// @grant GM_getValue
// @grant GM.getValue
// @grant GM_setValue
// @grant GM.setValue
// @grant unsafeWindow
// @require ${js_env ? `http://localhost:8080/jquery.slim.min.js` : `https://code.jquery.com/jquery-3.6.1.slim.min.js`}
// @resource uiJs ${js_env ? `http://localhost:8080/ui.js?_=${time}` : `https://cdn.jsdelivr.net/gh/magicoflolis/Userscript-Plus@master/dist/ui.js`}
// @resource gfcount https://greasyfork.org/scripts/by-site.json
// @resource sfcount https://sleazyfork.org/scripts/by-site.json
// @resource sfcount https://sleazyfork.org/scripts/by-site.json
// @require ${js_env ? `https://cdn.jsdelivr.net/gh/jquery/jquery/dist/jquery.slim.min.js` : `https://code.jquery.com/jquery-3.6.1.slim.min.js`}
// @resource uiJs ${js_env ? `http://localhost:8080/ui.js?_=${time}` : `https://cdn.jsdelivr.net/gh/magicoflolis/Userscript-Plus@master/dist/ui.js`}