Greasy Fork++

添加各种功能并改善 Greasy Fork 体验

当前为 2023-12-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Greasy Fork++
  3. // @namespace https://github.com/iFelix18
  4. // @version 3.2.37
  5. // @author CY Fung <https://greasyfork.org/users/371179> & Davide <iFelix18@protonmail.com>
  6. // @icon https://www.google.com/s2/favicons?domain=https://greasyfork.org
  7. // @description Adds various features and improves the Greasy Fork experience
  8. // @description:de Fügt verschiedene Funktionen hinzu und verbessert das Greasy Fork-Erlebnis
  9. // @description:es Agrega varias funciones y mejora la experiencia de Greasy Fork
  10. // @description:fr Ajoute diverses fonctionnalités et améliore l'expérience Greasy Fork
  11. // @description:it Aggiunge varie funzionalità e migliora l'esperienza di Greasy Fork
  12. // @description:ru Добавляет различные функции и улучшает работу с Greasy Fork
  13. // @description:zh-CN 添加各种功能并改善 Greasy Fork 体验
  14. // @description:zh-TW 加入多種功能並改善Greasy Fork的體驗
  15. // @description:ja Greasy Forkの体験を向上させる様々な機能を追加
  16. // @description:ko Greasy Fork 경험을 향상시키고 다양한 기능을 추가
  17. // @copyright 2023, CY Fung (https://greasyfork.org/users/371179); 2021, Davide (https://github.com/iFelix18)
  18. // @license MIT
  19. // @require https://fastly.jsdelivr.net/gh/sizzlemctwizzle/GM_config@06f2015c04db3aaab9717298394ca4f025802873/gm_config.min.js
  20. // @require https://fastly.jsdelivr.net/npm/@violentmonkey/shortcut@1.4.1/dist/index.min.js
  21. // @require https://fastly.jsdelivr.net/gh/cyfung1031/userscript-supports@3fa07109efca28a21094488431363862ccd52d7c/library/WinComm.min.js
  22. // @match *://greasyfork.org/*
  23. // @match *://sleazyfork.org/*
  24. // @connect greasyfork.org
  25. // @compatible chrome
  26. // @compatible edge
  27. // @compatible firefox
  28. // @compatible safari
  29. // @compatible brave
  30. // @grant GM.deleteValue
  31. // @grant GM.getValue
  32. // @grant GM.notification
  33. // @grant GM.registerMenuCommand
  34. // @grant GM.setValue
  35. // @grant unsafeWindow
  36. // @run-at document-start
  37. // @inject-into content
  38. // ==/UserScript==
  39.  
  40. /* global GM_config, VM, GM, WinComm */
  41.  
  42. /**
  43. * @typedef { typeof import("./library/WinComm.js") } WinComm
  44. */
  45.  
  46. // console.log(GM)
  47.  
  48. /** @type {WinComm} */
  49. const WinComm = this.WinComm;
  50.  
  51. // -------- UU Fucntion - original code: https://fastly.jsdelivr.net/npm/@ifelix18/utils@6.5.0/lib/index.min.js --------
  52. // optimized by CY Fung to remove $ dependency and observe creation
  53. const UU = (function () {
  54. const scriptName = GM.info.script.name; // not name_i18n
  55. const scriptVersion = GM.info.script.version;
  56. const authorMatch = /^(.*?)\s<\S[^\s@]*@\S[^\s.]*\.\S+>$/.exec(GM.info.script.author);
  57. const author = authorMatch ? authorMatch[1] : GM.info.script.author;
  58. let scriptId = scriptName.toLowerCase().replace(/\s/g, "-");
  59. let loggingEnabled = false;
  60.  
  61. const log = (message) => {
  62. if (loggingEnabled) {
  63. console.log(`${scriptName}:`, message);
  64. }
  65. };
  66.  
  67. const error = (message) => {
  68. console.error(`${scriptName}:`, message);
  69. };
  70.  
  71. const warn = (message) => {
  72. console.warn(`${scriptName}:`, message);
  73. };
  74.  
  75. const alert = (message) => {
  76. window.alert(`${scriptName}: ${message}`);
  77. };
  78.  
  79. /** @param {string} text */
  80. const short = (text, length) => {
  81. const s = text.split(" ");
  82. const l = Number(length);
  83. return s.length > l
  84. ? `${s.slice(0, l).join(" ")} [...]`
  85. : text;
  86. };
  87.  
  88. const addStyle = (css) => {
  89. const head = document.head || document.querySelector("head");
  90. const style = document.createElement("style");
  91. style.textContent = css;
  92. head.appendChild(style);
  93. };
  94.  
  95. const init = async (options = {}) => {
  96. scriptId = options.id || scriptId;
  97. loggingEnabled = typeof options.logging === "boolean" ? options.logging : false;
  98. console.info(
  99. `%c${scriptName}\n%cv${scriptVersion}${author ? ` by ${author}` : ""} is running!`,
  100. "color:red;font-weight:700;font-size:18px;text-transform:uppercase",
  101. ""
  102. );
  103. };
  104.  
  105. return {
  106. init,
  107. log,
  108. error,
  109. warn,
  110. alert,
  111. short,
  112. addStyle
  113. };
  114. })();
  115.  
  116. // -------- UU Fucntion - original code: https://fastly.jsdelivr.net/npm/@ifelix18/utils@6.5.0/lib/index.min.js --------
  117.  
  118.  
  119. const mWindow = (() => {
  120.  
  121.  
  122. const fields = {
  123. hideBlacklistedScripts: {
  124. label: 'Hide blacklisted scripts:<br><span>Choose which lists to activate in the section below, press <b>Ctrl + Alt + B</b> to show Blacklisted scripts</span>',
  125. section: ['Features'],
  126. labelPos: 'right',
  127. type: 'checkbox',
  128. default: true
  129. },
  130. hideHiddenScript: {
  131. label: 'Hide scripts:<br><span>Add a button to hide the script<br>See and edit the list of hidden scripts below, press <b>Ctrl + Alt + H</b> to show Hidden script',
  132. labelPos: 'right',
  133. type: 'checkbox',
  134. default: true
  135. },
  136. showInstallButton: {
  137. label: 'Install button:<br><span>Add to the scripts list a button to install the script directly</span>',
  138. labelPos: 'right',
  139. type: 'checkbox',
  140. default: true
  141. },
  142. showTotalInstalls: {
  143. label: 'Installations:<br><span>Shows the number of daily and total installations on the user profile</span>',
  144. labelPos: 'right',
  145. type: 'checkbox',
  146. default: true
  147. },
  148. milestoneNotification: {
  149. label: 'Milestone notifications:<br><span>Get notified whenever your total installs got over any of these milestone<br>Separate milestones with a comma, leave blank to turn off notifications</span>',
  150. labelPos: 'left',
  151. type: 'text',
  152. title: 'Separate milestones with a comma!',
  153. size: 150,
  154. default: '10, 100, 500, 1000, 2500, 5000, 10000, 100000, 1000000'
  155. },
  156. nonLatins: {
  157. label: 'Non-Latin:<br><span>This list blocks all scripts with non-Latin characters in the title/description</span>',
  158. section: ['Lists'],
  159. labelPos: 'right',
  160. type: 'checkbox',
  161. default: false // not true
  162. },
  163. blacklist: {
  164. label: 'Blacklist:<br><span>A "non-opinionable" list that blocks all scripts with emoji in the title/description, references to "bots", "cheats" and some online game sites, and other "bullshit"</span>',
  165. labelPos: 'right',
  166. type: 'checkbox',
  167. default: true
  168. },
  169. customBlacklist: {
  170. label: 'Custom Blacklist:<br><span>Personal blacklist defined by a set of unwanted words<br>Separate unwanted words with a comma (example: YouTube, Facebook, pizza), leave blank to disable this list</span>',
  171. labelPos: 'left',
  172. type: 'text',
  173. title: 'Separate unwanted words with a comma!',
  174. size: 150,
  175. default: ''
  176. },
  177. hiddenList: {
  178. label: 'Hidden Scripts:<br><span>Block individual undesired scripts by their unique IDs<br>Separate IDs with a comma</span>',
  179. labelPos: 'left',
  180. type: 'textarea',
  181. title: 'Separate IDs with a comma!',
  182. default: '',
  183. save: false
  184. },
  185. logging: {
  186. label: 'Logging',
  187. section: ['Developer options'],
  188. labelPos: 'right',
  189. type: 'checkbox',
  190. default: false
  191. },
  192. debugging: {
  193. label: 'Debugging',
  194. labelPos: 'right',
  195. type: 'checkbox',
  196. default: false
  197. }
  198. }
  199.  
  200. const logo = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAMAAADVRocKAAAASFBMVEVHcEwBAQEDAwMAAAACAgIBAQEAAAAREREDAwMBAQH///8WFhYuLi7U1NSdnZ1bW1vExMTq6uqtra309PRERETf399ycnKGhoaVOQEOAAAACnRSTlMAg87/rjLgE1rzhWrqxgAABexJREFUaN61WouSpCAMVPEJKCqi//+nF4IKKig6e1SduzfupEkT8oIkiRlVVdRpnmdlQ0hTZnme1kVV4Zvk96Fla8nH0ZSI8rP0Ks2uwi1Ilv4EURW5K5xS0slhMb/BkD0hrMk/q1HVeSP6QVILMFIY8wagn6ojTV5Xn8RnbFZaoAPQc9bR3gXQ/yaWvYYA8VfKKeXACZVnAE1V9o4on/izWPsb/q9Ji3j5OcrjhiCXohsAQso6lh6QL9qOEd6GAAbKYAInAFAiiqYC5LMeLIaFKeppR3h/BiAkj6CpLuEPmbbHngUBhFZsdAGiaUL5xLBzRrAAZBlk5wpnVJEohHTbuZoAD0uhMUu+uY/bLZHaryBCH4vQCuugbnSoYf5sk+llKWaEETT/Qu2TecmSHaF1KPT6gmkM4hNLLkIR2l/guAZK1fQrS3kVXmChEX5mKb0xICH/gKXrQtf2pbhlyfqFoL/1LUOVEbFwcsuSs5GfAcjJ8dVkknbafpYUfUXSQYWqRP81THcs8fbVMmTVaQU6ENNOdyxNgGRYmFsp2/mQaFiKzGeC1IcVmAjrDjq4LAF9RgdF13CAo3cTDRcAP2OOCjX6UAwCPpbWyGZsCWTMAM0YTGF2Eg0XAD8bramue9jocGVpi5y7LbUUVRO0dRINF2D9bN/PBSqgAizt8gHByJAUddEyTqa7rYF57oZkkgiYj48lYeVTuuh4Hw1A8pWhxr68snQYioOxHSm6A2gq1wuZz68suUMKELst8oCLfAew+rzMecmOLO251wYwa4CDmd4B8GyPM1YDlyXeUp8Gx412A9Chy6vP9cXO0kW+5e6N104vH68sXeW/jwzptss8OihFf1UAY2dVkgDCdQz8dfiv1m3sZek62rcIsJlr/5uADv1bhNqzxrcIb3VIkzz06m9YykMAM39kidIoAG+5R7icHlm6BViUVDqSZknpfd8NZh2MO1Xz+JKlcYsfZeK3UqjBTDRexn680PVoSxMFBiCST6RJJmXzg2FTegaPzyRWRWu9cERAHW4o6jANmPU0Ewwqe36wa8j1wyQLADHyk1FphM760H1sBY/+PtS5ECQTvucHynoapYPiZJKFDoSNnFxZYl0QYG2gQExtcJFN8LNl1voHOA++5yQelh5yVPhRopma8M3OALMO8p0GhgDT+lgKDatBhhvN5gcuRWaZJeQ8CzVBLmBLd2tgdrLND9xFxh9CW8JABYRSNQVYugJYK8rB2bn5gWOmaM4dzmXQVjvuidMzS3YfpEm9uPnBtp5yNFRJLRUTb9OaiN1x+06uk0q4+cG+U+SqCeoKLmMwrYkp1pYWRbUvgoDjDZng7EScG3/wSxAyK7+/Xvrgl974JZ1gp69r1Bc7LvUlXhEIsSxh4lWU5Ecdwixh6lhlhPwvlkyZlpIvCFEspW4B8h9YWguQYOZynzZEsJTvRWBPxwDABnKuXWJY2ovAKu8H9h7gkSXblqqFIB8AHlhyekbGUk2PYUbXtvgAXGnYjfWwNA+QcDHN3+x2Q2rngENgiSeeAUZfjDMVHkSn1m2GGBVwCh0d8NlfhJ4owiyE+VjiPV0WKQ7tHCxD1h6DeQ7PAMKWvUcERtt2PDakkio9f/1pkdcsxMOSLq7ldD5LAJf3BeCaCfQmDl57s/Xak4sHEJiPjOcdN4f61+n8CDDQaX/iIk8KcrOTDqCC4Km3tdw9AeBM1+dq1IqRE0stI8LbWk6K7AmAjYPeX/jEdF/qJtgpX+pDzfH9eCVunFyt1UEQUt8dUHwE2BE6b2f8A8I1WMxqGLQfyqu7I8zmOwBh08TJrfy36+ANw1XcQdrHEXOeWeTf5edRJ7JV+t/o+UKTc+hRxx8oF+lLaxKCvTmw1vcRshcAbGFZ8eFUv4kF4NnHewn5pM91sauv7z9gumDPPNgoobBq54/XHraLGyAZXPLqaFrnzIMpKoeR/3BxY7t6woWY2hYqZZ0u2DOPeZzZr1dP7OUZbk4MVE+wecrmqcn+5vLMevsneP3ncfwDNtu0vRpuz80AAAAASUVORK5CYII='
  201.  
  202. const locales = { /* cSpell: disable */
  203. de: {
  204. downgrade: 'Auf zurückstufen',
  205. hide: '❌ Dieses skript ausblenden',
  206. install: 'Installieren',
  207. notHide: '✔️ Dieses skript nicht ausblenden',
  208. milestone: 'Herzlichen Glückwunsch, Ihre Skripte haben den Meilenstein von insgesamt $1 Installationen überschritten!',
  209. reinstall: 'Erneut installieren',
  210. update: 'Auf aktualisieren'
  211. },
  212. en: {
  213. downgrade: 'Downgrade to',
  214. hide: '❌ Hide this script',
  215. install: 'Install',
  216. notHide: '✔️ Not hide this script',
  217. milestone: 'Congrats, your scripts got over the milestone of $1 total installs!',
  218. reinstall: 'Reinstall',
  219. update: 'Update to'
  220. },
  221. es: {
  222. downgrade: 'Degradar a',
  223. hide: '❌ Ocultar este script',
  224. install: 'Instalar',
  225. notHide: '✔️ No ocultar este script',
  226. milestone: '¡Felicidades, sus scripts superaron el hito de $1 instalaciones totales!',
  227. reinstall: 'Reinstalar',
  228. update: 'Actualizar a'
  229. },
  230. fr: {
  231. downgrade: 'Revenir à',
  232. hide: '❌ Cacher ce script',
  233. install: 'Installer',
  234. notHide: '✔️ Ne pas cacher ce script',
  235. milestone: 'Félicitations, vos scripts ont franchi le cap des $1 installations au total!',
  236. reinstall: 'Réinstaller',
  237. update: 'Mettre à'
  238. },
  239. it: {
  240. downgrade: 'Riporta a',
  241. hide: '❌ Nascondi questo script',
  242. install: 'Installa',
  243. notHide: '✔️ Non nascondere questo script',
  244. milestone: 'Congratulazioni, i tuoi script hanno superato il traguardo di $1 installazioni totali!',
  245. reinstall: 'Reinstalla',
  246. update: 'Aggiorna a'
  247. },
  248. ru: {
  249. downgrade: 'Откатить до',
  250. hide: '❌ Скрыть этот скрипт',
  251. install: 'Установить',
  252. notHide: '✔️ Не скрывать этот сценарий',
  253. milestone: 'Поздравляем, ваши скрипты преодолели рубеж в $1 установок!',
  254. reinstall: 'Переустановить',
  255. update: 'Обновить до'
  256. },
  257. 'zh-CN': {
  258. downgrade: '降级到',
  259. hide: '❌ 隐藏此脚本',
  260. install: '安装',
  261. notHide: '✔️ 不隐藏此脚本',
  262. milestone: '恭喜,您的脚本超过了 $1 次总安装的里程碑!',
  263. reinstall: '重新安装',
  264. update: '更新到'
  265. },
  266. 'zh-TW': {
  267. downgrade: '降級至',
  268. hide: '❌ 隱藏此腳本',
  269. install: '安裝',
  270. notHide: '✔️ 不隱藏此腳本',
  271. milestone: '恭喜,您的腳本安裝總數已超過 $1!',
  272. reinstall: '重新安裝',
  273. update: '更新至'
  274. },
  275. 'ja': {
  276. downgrade: 'ダウングレードする',
  277. hide: '❌ このスクリプトを隠す',
  278. install: 'インストール',
  279. notHide: '✔️ このスクリプトを隠さない',
  280. milestone: 'おめでとうございます、あなたのスクリプトの合計インストール回数が $1 を超えました!',
  281. reinstall: '再インストール',
  282. update: '更新する'
  283. },
  284. 'ko': {
  285. downgrade: '다운그레이드하기',
  286. hide: '❌ 이 스크립트 숨기기',
  287. install: '설치',
  288. notHide: '✔️ 이 스크립트 숨기지 않기',
  289. milestone: '축하합니다, 스크립트의 총 설치 횟수가 $1을 넘었습니다!',
  290. reinstall: '재설치',
  291. update: '업데이트하기'
  292. }
  293.  
  294. };
  295.  
  296. const blacklist = [ /* cSpell: disable-next-line */
  297. '\\bagar((\\.)?io)?\\b', '\\bagma((\\.)?io)?\\b', '\\baimbot\\b', '\\barras((\\.)?io)?\\b', '\\bbot(s)?\\b', '\\bbubble((\\.)?am)?\\b', '\\bcheat(s)?\\b', '\\bdiep((\\.)?io)?\\b', '\\bfreebitco((\\.)?in)?\\b', '\\bgota((\\.)?io)?\\b', '\\bhack(s)?\\b', '\\bkrunker((\\.)?io)?\\b', '\\blostworld((\\.)?io)?\\b', '\\bmoomoo((\\.)?io)?\\b', '\\broblox(\\.com)?\\b', '\\bshell\\sshockers\\b', '\\bshellshock((\\.)?io)?\\b', '\\bshellshockers\\b', '\\bskribbl((\\.)?io)?\\b', '\\bslither((\\.)?io)?\\b', '\\bsurviv((\\.)?io)?\\b', '\\btaming((\\.)?io)?\\b', '\\bvenge((\\.)?io)?\\b', '\\bvertix((\\.)?io)?\\b', '\\bzombs((\\.)?io)?\\b', '\\p{Extended_Pictographic}'
  298. ];
  299.  
  300.  
  301. const settingsCSS = `
  302.  
  303. /*
  304. #greasyfork-plus label::before {
  305. content:'';
  306. display:block;
  307. position:absolute;
  308. left:0;
  309. right:0;
  310. top:0;
  311. bottom:0;
  312. z-index:1;
  313. }
  314. #greasyfork-plus label {
  315. position:relative;
  316. z-index:0;
  317. }
  318. */
  319.  
  320. html {
  321. color: #222;
  322. background: #f9f9f9;
  323. }
  324.  
  325. #greasyfork-plus{
  326. --config-var-display: flex;
  327. }
  328. #greasyfork-plus * {
  329. font-family:Open Sans,sans-serif,Segoe UI Emoji !important;
  330. font-size:12px
  331. }
  332. #greasyfork-plus .section_header[class] {
  333. background-color:#670000;
  334. background-image:linear-gradient(#670000,#900);
  335. border:1px solid transparent;
  336. color:#fff
  337. }
  338. #greasyfork-plus .field_label[class]{
  339. margin-bottom:4px
  340. }
  341. #greasyfork-plus .field_label[class] span{
  342. font-size:95%;
  343. font-style:italic;
  344. opacity:.8;
  345. }
  346. #greasyfork-plus .field_label[class] b{
  347. color:#670000
  348. }
  349. #greasyfork-plus_logging_var[class],
  350. #greasyfork-plus_debugging_var[class] {
  351. --config-var-display: inline-flex;
  352. }
  353. #greasyfork-plus #greasyfork-plus_logging_var label.field_label[class],
  354. #greasyfork-plus #greasyfork-plus_debugging_var label.field_label[class] {
  355. margin-bottom:0;
  356. align-self: center;
  357. }
  358. #greasyfork-plus .config_var[class]{
  359. display:var(--config-var-display);
  360. position: relative;
  361. }
  362. #greasyfork-plus_customBlacklist_var[class],
  363. #greasyfork-plus_hiddenList_var[class],
  364. #greasyfork-plus_milestoneNotification_var[class]{
  365. flex-direction:column;
  366. margin-left:21px;
  367. }
  368.  
  369. #greasyfork-plus_customBlacklist_var[class]::before,
  370. #greasyfork-plus_hiddenList_var[class]::before,
  371. #greasyfork-plus_milestoneNotification_var[class]::before{
  372. /* content: "◉"; */
  373. content: "◎";
  374. position: absolute;
  375. left: auto;
  376. top: auto;
  377. margin-left: -16px;
  378. }
  379. #greasyfork-plus_field_customBlacklist[class],
  380. #greasyfork-plus_field_milestoneNotification[class]{
  381. flex:1;
  382. }
  383. #greasyfork-plus_field_hiddenList[class]{
  384. box-sizing:border-box;
  385. overflow:hidden;
  386. resize:none;
  387. width:100%
  388. }
  389.  
  390. body > #greasyfork-plus_wrapper:only-child {
  391. box-sizing: border-box;
  392. overflow: auto;
  393. max-height: calc(100vh - 72px);
  394. padding: 12px;
  395. /* overflow: auto; */
  396. scrollbar-gutter: both-edges;
  397. background: rgba(127,127,127,0.05);
  398. border: 1px solid rgba(127,127,127,0.5);
  399. }
  400.  
  401. #greasyfork-plus_wrapper > #greasyfork-plus_buttons_holder:last-child {
  402. position: fixed;
  403. bottom: 0;
  404. right: 0;
  405. margin: 0 12px 6px 0;
  406. }
  407.  
  408. #greasyfork-plus .saveclose_buttons[class] {
  409. padding: 4px 14px;
  410. margin: 6px;
  411. }
  412. #greasyfork-plus .section_header_holder#greasyfork-plus_section_2[class] {
  413. position: fixed;
  414. left: 0;
  415. bottom: 0;
  416. margin: 8px;
  417. }
  418. #greasyfork-plus .section_header#greasyfork-plus_section_header_2[class] {
  419. background: #000;
  420. color: #eee;
  421. }
  422.  
  423. #greasyfork-plus_header[class]{
  424. font-size: 16pt;
  425. font-weight: bold;
  426. }
  427.  
  428. `;
  429.  
  430. const pageCSS = `
  431.  
  432. .script-list li.blacklisted{
  433. display:none;
  434. background:#321919;
  435. color:#e8e6e3
  436. }
  437. .script-list li.hidden{
  438. display:none;
  439. background:#321932;
  440. color:#e8e6e3
  441. }
  442. .script-list li.blacklisted a:not(.install-link),.script-list li.hidden a:not(.install-link){
  443. color:#ff8484
  444. }
  445. #script-info.hidden,#script-info.hidden .user-content{
  446. background:#321932;
  447. color:#e8e6e3
  448. }
  449. #script-info.hidden a:not(.install-link):not(.install-help-link){
  450. color:#ff8484
  451. }
  452. #script-info.hidden code{
  453. background-color:transparent
  454. }
  455. html {
  456. --block-btn-color:#111;
  457. --block-btn-bgcolor:#eee;
  458. }
  459. #script-info.hidden, #script-info.hidden .user-content {
  460. --block-btn-color:#eee;
  461. --block-btn-bgcolor:#111;
  462. }
  463.  
  464. [style-54998]{
  465. float:right;
  466. font-size: 70%;
  467. text-decoration:none;
  468. }
  469.  
  470. [style-16377]{
  471. cursor:pointer;
  472. font-size:70%;
  473. white-space:nowrap;
  474. border: 1px solid #888;
  475. background: var(--block-btn-bgcolor, #eee);
  476. color: var(--block-btn-color);
  477. border-radius: 4px;
  478. padding: 0px 6px;
  479. margin: 0 8px;
  480. }
  481. [style-77329] {
  482. cursor: pointer;
  483. margin-left: 1ex;
  484. white-space: nowrap;
  485. float: right;
  486. border: 1px solid #888;
  487. background: var(--block-btn-bgcolor, #eee);
  488. color: var(--block-btn-color);
  489. border-radius: 4px;
  490. padding: 0px 6px;
  491. }
  492.  
  493. a#hyperlink-35389,
  494. a#hyperlink-40361,
  495. a#hyperlink-35389:visited,
  496. a#hyperlink-40361:visited,
  497. a#hyperlink-35389:hover,
  498. a#hyperlink-40361:hover,
  499. a#hyperlink-35389:focus,
  500. a#hyperlink-40361:focus,
  501. a#hyperlink-35389:active,
  502. a#hyperlink-40361:active {
  503.  
  504. border: none !important;
  505. outline: none !important;
  506. box-shadow: none !important;
  507. appearance: none !important;
  508. background: none !important;
  509. color:inherit !important;
  510. }
  511.  
  512. a#hyperlink-35389{
  513. opacity: var(--hyperlink-blacklisted-option-opacity);
  514.  
  515. }
  516. a#hyperlink-40361{
  517. opacity: var(--hyperlink-hidden-option-opacity);
  518. }
  519.  
  520.  
  521. html {
  522.  
  523. --hyperlink-blacklisted-option-opacity: 0.5;
  524. --hyperlink-hidden-option-opacity: 0.5;
  525. }
  526.  
  527.  
  528. .list-option.list-current[class] > a[href] {
  529.  
  530. text-decoration:none;
  531. }
  532.  
  533. html {
  534. --blacklisted-display: none;
  535. --hidden-display: none;
  536. }
  537.  
  538. [blacklisted-shown] {
  539. --blacklisted-display: list-item;
  540. --hyperlink-blacklisted-option-opacity: 1;
  541. }
  542. [hidden-shown] {
  543. --hidden-display: list-item;
  544. --hyperlink-hidden-option-opacity: 1;
  545. }
  546.  
  547. .script-list li.blacklisted{
  548. display: var(--blacklisted-display);
  549.  
  550. }
  551.  
  552. .script-list li.hidden{
  553. display: var(--hidden-display);
  554.  
  555. }
  556.  
  557. .install-link.install-status-checking,
  558. .install-link.install-status-checking:visited,
  559. .install-link.install-status-checking:active,
  560. .install-link.install-status-checking:hover,
  561. .install-help-link.install-status-checking {
  562. background-color: #405458;
  563. }
  564.  
  565. div.previewable{
  566. display: flex;
  567. flex-direction: column;
  568. }
  569. .script-version-ainfo-span {
  570. align-self:end;
  571. font-size: 90%;
  572. padding: 4px 8px;
  573. margin: 0;
  574. }
  575. [style*="display:"] + .script-version-ainfo-span{
  576. display: none;
  577. }
  578.  
  579.  
  580. /* Greasy Fork Enhance - Flat Layout */
  581.  
  582. [greasyfork-enhance-k37*="|flat-layout|"] ol.script-list > li > article > h2 {
  583. width: 0;
  584. flex-grow: 1;
  585. flex-basis: 60%;
  586. }
  587.  
  588. [greasyfork-enhance-k37*="|flat-layout|"] ol.script-list > li > article > div.script-meta-block {
  589. width: auto;
  590. flex-basis: 40%;
  591. flex-shrink: 0;
  592. flex-grow: 0;
  593. }
  594.  
  595. [greasyfork-enhance-k37*="|flat-layout|"] .script-list li:not(.ad-entry) {
  596. padding: 1em;
  597. margin: 0;
  598. }
  599.  
  600. [greasyfork-enhance-k37*="|flat-layout|"] .script-list li:not(.ad-entry) article {
  601. padding: 0;
  602. margin: 0;
  603. }
  604.  
  605. [greasyfork-enhance-k37*="|flat-layout|"] #script-info div.script-meta-block + #additional-info {
  606.  
  607. max-width: calc( 100% - 340px );
  608. min-height: 300px;
  609. box-sizing: border-box;
  610. }
  611.  
  612. [greasyfork-enhance-k37*="|basic|"] ul.outline {
  613. margin-bottom: -99vh;
  614.  
  615. }
  616.  
  617.  
  618. `
  619.  
  620. const window = {};
  621.  
  622. /** @param {typeof WinComm.createInstance} createInstance */
  623. function contentScriptText(shObject, createInstance) {
  624.  
  625. /*
  626. *
  627.  
  628. return new Promise((resolve, reject) => {
  629. const external = unsafeWindow.external;
  630. console.log(334, external)
  631. const scriptHandler = GM.info.scriptHandler;
  632. if (external && external.Violentmonkey && (scriptHandler || 'Violentmonkey') === 'Violentmonkey' ) {
  633. external.Violentmonkey.isInstalled(name, namespace).then((data) => resolve(data));
  634. return;
  635. }
  636.  
  637. if (external && external.Tampermonkey && (scriptHandler || 'Tampermonkey') === 'Tampermonkey') {
  638. external.Tampermonkey.isInstalled(name, namespace, (data) => {
  639. (data.installed) ? resolve(data.version) : resolve();
  640. });
  641. return;
  642. }
  643.  
  644. resolve();
  645. });
  646.  
  647. */
  648.  
  649. if (document.querySelector('#greasyfork-enhance-basic')) {
  650.  
  651.  
  652.  
  653. const setScriptOnDisabled = async (style) => {
  654.  
  655. try {
  656. const pd = Object.getOwnPropertyDescriptor(style.constructor.prototype, 'disabled');
  657. const { get, set } = pd;
  658. Object.defineProperty(style, 'disabled', {
  659. get() {
  660. return get.call(this);
  661. },
  662. set(nv) {
  663. let r = set.call(this, nv);
  664. Promise.resolve().then(chHead);
  665. return r;
  666. }
  667. })
  668. } catch (e) {
  669.  
  670. }
  671. };
  672.  
  673. document.addEventListener('style-s48', function (evt) {
  674. const target = (evt || 0).target || 0;
  675. if (!target) return;
  676. setScriptOnDisabled(target)
  677.  
  678. }, true);
  679.  
  680.  
  681. const isScriptEnabled = (style) => {
  682.  
  683. if (style instanceof HTMLStyleElement) {
  684. if (!style.hasAttribute('s48')) {
  685. style.setAttribute('s48', '');
  686. style.dispatchEvent(new CustomEvent('style-s48'));
  687. // setScriptOnDisabled(style);
  688. }
  689. return style.disabled !== true;
  690. }
  691. return false;
  692. }
  693. const chHead = () => {
  694. let p = [];
  695. if (isScriptEnabled(document.getElementById('greasyfork-enhance-basic')))
  696. p.push('basic');
  697. if (isScriptEnabled(document.getElementById('greasyfork-enhance-flat-layout')))
  698. p.push('flat-layout');
  699. if (isScriptEnabled(document.getElementById('greasyfork-enhance-animation')))
  700. p.push('animation');
  701. if (p.length >= 1)
  702. document.documentElement.setAttribute('greasyfork-enhance-k37', `|${p.join('|')}|`);
  703. else
  704. document.documentElement.removeAttribute('greasyfork-enhance-k37');
  705. }
  706. const moHead = new MutationObserver(chHead);
  707. moHead.observe(document.head, { subtree: false, childList: true });
  708. chHead();
  709.  
  710. /*
  711. const outline = document.querySelector('aside.panel > ul.outline');
  712. if(outline) {
  713. const div = document.createElement('div');
  714. //outline.replaceWith(div);
  715. //div.appendChild(outline)
  716. }
  717. */
  718.  
  719. // Promise.resolve().then(()=>{
  720. // let outline = document.querySelector('[greasyfork-enhance-k37*="|basic|"] header + aside.panel ul.outline');
  721. // if(outline){
  722. // let aside = outline.closest('aside.panel');
  723. // let header = aside.parentNode.querySelector('header');
  724. // let p = header.getBoundingClientRect().height;
  725.  
  726. // document.body.parentNode.insertBefore(aside, document.body);
  727. // // outline.style.top='0'
  728. // p+=(parseFloat(getComputedStyle(outline).marginTop.replace('px',''))||0)
  729. // outline.style.marginTop= p.toFixed(2)+'px';
  730. // }
  731.  
  732. // })
  733.  
  734. }
  735.  
  736.  
  737.  
  738. const { scriptHandler, scriptName, scriptVersion, scriptNamespace, communicationId } = shObject;
  739.  
  740. const wincomm = createInstance(communicationId);
  741.  
  742. const external = window.external;
  743.  
  744. if (external[scriptHandler]) 1;
  745. else if (external && external.Violentmonkey && (scriptHandler || 'Violentmonkey') === 'Violentmonkey') scriptHandler = 'Violentmonkey';
  746. else if (external && external.Tampermonkey && (scriptHandler || 'Tampermonkey') === 'Tampermonkey') scriptHandler = 'Tampermonkey';
  747.  
  748. const manager = external[scriptHandler];
  749.  
  750. if (!manager) {
  751.  
  752. wincomm.send('userScriptManagerNotDetected', {
  753. code: 1
  754. });
  755. return;
  756.  
  757. }
  758.  
  759.  
  760. const pnIsInstalled2 = (type, scriptName, scriptNamespace) => new Promise((resolve, reject) => {
  761. const result = manager.isInstalled(scriptName, scriptNamespace);
  762. if (result instanceof Promise) {
  763. result.then((result) => resolve({
  764. type,
  765. result: typeof result === 'string' ? { version: result } : result
  766. })).catch(reject);
  767. } else {
  768. resolve({
  769. type,
  770. result: typeof result === 'string' ? { version: result } : result
  771. })
  772. }
  773.  
  774. }).catch(console.warn);
  775.  
  776.  
  777. const pnIsInstalled3 = (type, scriptName, scriptNamespace) => new Promise((resolve, reject) => {
  778. try {
  779. manager.isInstalled(scriptName, scriptNamespace, (result) => {
  780. resolve({
  781. type,
  782. result: typeof result === 'string' ? { version: result } : result
  783. })
  784.  
  785. });
  786. } catch (e) {
  787. reject(e);
  788. }
  789. }).catch(console.warn);
  790.  
  791.  
  792.  
  793. const enableScriptInstallChecker = (r) => {
  794.  
  795. const { type, result } = r;
  796. let version = result.version;
  797. // console.log(type, result, version)
  798. if (version !== scriptVersion) return;
  799.  
  800. const pnIsInstalled = type < 25 ? pnIsInstalled2 : pnIsInstalled3;
  801.  
  802. wincomm.hook('_$GreasyFork$Msg$OnScriptInstallCheck', {
  803.  
  804. 'installedVersion.req': (d, evt) => {
  805. pnIsInstalled(type, d.data.name, d.data.namespace).then((r) => {
  806. if (r && 'result' in r) {
  807. wincomm.response(evt, 'installedVersion.res', {
  808. version: r.result ? (r.result.version || '') : ''
  809. });
  810. }
  811. })
  812. }
  813.  
  814. });
  815.  
  816. wincomm.send('ready', { type });
  817.  
  818. // console.log('enableScriptInstallChecker', r)
  819.  
  820.  
  821. }
  822.  
  823. const kl = manager.isInstalled.length;
  824.  
  825. if (!(kl === 2 || kl === 3)) return;
  826. const puds = kl === 2 ? [
  827. pnIsInstalled2(21, scriptName, scriptNamespace), // scriptName is GM.info.script.name not GM.info.script.name_i18n
  828. pnIsInstalled2(20, scriptName, '')
  829. ] : [
  830. pnIsInstalled3(31, scriptName, scriptNamespace),
  831. pnIsInstalled3(30, scriptName, '')
  832. ];
  833.  
  834. Promise.all(puds).then((rs) => {
  835. const [r1, r0] = rs;
  836. if (r0 && r0.result && r0.result.version) enableScriptInstallChecker(r0); // '3.1.4'
  837. else if (r1 && r1.result && r1.result.version) enableScriptInstallChecker(r1);
  838. });
  839.  
  840.  
  841.  
  842. // console.log(327, shObject, scriptHandler);
  843.  
  844. }
  845.  
  846.  
  847.  
  848. return { fields, logo, locales, blacklist, settingsCSS, pageCSS, contentScriptText }
  849.  
  850.  
  851.  
  852. })();
  853.  
  854. (async () => {
  855.  
  856. const isVaildURL = (url) => {
  857. if (!url || typeof url !== 'string' || url.length < 23) return;
  858. let obj = null;
  859. try {
  860. obj = new URL(url);
  861. } catch (e) {
  862. return false;
  863. }
  864. if (obj && obj.host === obj.hostname && !obj.port && (obj.protocol || '').startsWith('http') && obj.pathname) {
  865. return true;
  866. }
  867. return false;
  868. };
  869.  
  870. const installLinkPointerDownHandler = function (e) {
  871. if (!e || !e.isTrusted) return;
  872. const button = e.target || this;
  873. if (button.hasAttribute('acnmd')) return;
  874. const href = button.href;
  875. if (!href || !isVaildURL(href)) return;
  876. if (/\.js[^-.\w\d\s:\/\\]*$/.test(href)) {
  877. fetch(href, {
  878. method: "GET",
  879. cache: 'reload',
  880. redirect: "follow"
  881. }).then(() => {
  882. console.debug('code url reloaded', href);
  883. }).catch((e) => {
  884. console.debug(e);
  885. });
  886. }
  887. button.setAttribute('acnmd', '');
  888. };
  889.  
  890. const setupInstallLink = (button) => {
  891. if (!button || button.className !== 'install-link' || button.nodeName !== "A" || !button.href) return button;
  892. button.addEventListener('pointerdown', installLinkPointerDownHandler);
  893. return button;
  894. };
  895.  
  896. function fixValue(key, def, test) {
  897. return GM.getValue(key, def).then((v) => test(v) || GM.deleteValue(key))
  898. }
  899.  
  900. function numberArr(arrVal) {
  901. if (!arrVal || typeof arrVal.length !== 'number') return [];
  902. return arrVal.filter(e => typeof e === 'number' && !isNaN(e))
  903. }
  904.  
  905. const isScriptFirstUse = await GM.getValue('firstUse', true);
  906. await Promise.all([
  907. fixValue('hiddenList', [], v => v && typeof v === 'object' && typeof v.length === 'number' && (v.length === 0 || typeof v[0] === 'number')),
  908. fixValue('lastMilestone', 0, v => v && typeof v === 'number' && v >= 0)
  909. ])
  910.  
  911. function createRE(t, ...opt) {
  912. try {
  913. return new RegExp(t, ...opt);
  914. } catch (e) { }
  915. return null;
  916. }
  917.  
  918. const useHashedScriptName = true;
  919. const fixLibraryScriptCodeLink = true;
  920. const addAdditionInfoLengthHint = true;
  921.  
  922. const id = 'greasyfork-plus';
  923. const title = `${GM.info.script.name} v${GM.info.script.version} Settings`;
  924. const fields = mWindow.fields;
  925. const logo = mWindow.logo;
  926. const nonLatins = /[^\p{Script=Latin}\p{Script=Common}\p{Script=Inherited}]/gu;
  927. const blacklist = createRE((mWindow.blacklist || []).join('|'), 'giu');
  928. const hiddenList = numberArr(await GM.getValue('hiddenList', []));
  929. const lang = document.documentElement.lang;
  930. const locales = mWindow.locales;
  931.  
  932. const _isBlackList = (text) => {
  933. if (!text || typeof text !== 'string') return false;
  934. if (text.includes('hack') && (text.includes('EXPERIMENT_FLAGS') || text.includes('yt.'))) return false;
  935. return blacklist.test(text);
  936. }
  937. const isBlackList = (name, description) => {
  938. // To be reviewed
  939. if (!blacklist) return false;
  940. return _isBlackList(name) || _isBlackList(description);
  941. }
  942.  
  943. function hiddenListStrToArr(str) {
  944. if (!str || typeof str !== 'string') str = '';
  945. return [...new Set(str ? numberArr(str.split(',').map(e => parseInt(e))) : [])];
  946. }
  947.  
  948. const gmc = new GM_config({
  949. id,
  950. title,
  951. fields,
  952. css: mWindow.settingsCSS,
  953. events: {
  954. init: () => {
  955. gmc.initializedResolve && gmc.initializedResolve();
  956. gmc.initializedResolve = null;
  957.  
  958. },
  959. /** @param {Document} document */
  960. open: async (document) => {
  961. const textarea = document.querySelector(`#${id}_field_hiddenList`);
  962.  
  963. const hiddenSet = new Set(numberArr(await GM.getValue('hiddenList', [])));
  964. if (hiddenSet.size !== 0) {
  965. const unsavedHiddenList = hiddenListStrToArr(gmc.get('hiddenList'));
  966. const unsavedHiddenSet = new Set(unsavedHiddenList);
  967.  
  968. const hasDifferentItems = [...hiddenSet].some(item => !unsavedHiddenSet.has(item)) || [...unsavedHiddenSet].some(item => !hiddenSet.has(item));
  969.  
  970. if (hasDifferentItems) {
  971.  
  972. gmc.fields.hiddenList.value = [...hiddenSet].sort((a, b) => a - b).join(', ');
  973.  
  974. gmc.close();
  975. gmc.open();
  976.  
  977. }
  978.  
  979.  
  980. }
  981.  
  982. const resize = (target) => {
  983. target.style.height = '';
  984. target.style.height = `${target.scrollHeight}px`;
  985. };
  986.  
  987. if (textarea) {
  988. resize(textarea);
  989. textarea.addEventListener('input', (event) => resize(event.target));
  990.  
  991. }
  992.  
  993. document.body.addEventListener('mousedown', (event) => {
  994. if (event.detail > 1 && !event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey && !event.defaultPrevented) {
  995. event.preventDefault();
  996. event.stopPropagation();
  997. event.stopImmediatePropagation();
  998. }
  999. }, true);
  1000. },
  1001. save: async (forgotten) => {
  1002.  
  1003. if (gmc.isOpen) {
  1004. await GM.setValue('hiddenList', hiddenListStrToArr(forgotten.hiddenList));
  1005.  
  1006. UU.alert('settings saved');
  1007. gmc.close();
  1008. setTimeout(() => window.location.reload(false), 500);
  1009. }
  1010. }
  1011. }
  1012. });
  1013. gmc.initialized = new Promise(r => (gmc.initializedResolve = r));
  1014. await gmc.initialized.then();
  1015. const customBlacklistRE = createRE((gmc.get('customBlacklist') || '').replace(/\s/g, '').split(',').join('|'), 'giu');
  1016.  
  1017. if (typeof GM.registerMenuCommand === 'function') {
  1018. GM.registerMenuCommand('Configure', () => gmc.open());
  1019. GM.registerMenuCommand('Reset Everything', () => {
  1020. Promise.all([
  1021. GM.deleteValue('hiddenList'),
  1022. GM.deleteValue('lastMilestone'),
  1023. GM.deleteValue('firstUse')
  1024. ]).then(() => {
  1025. setTimeout(() => window.location.reload(false), 50);
  1026. })
  1027. });
  1028. }
  1029.  
  1030. UU.init({ id, logging: gmc.get('logging') });
  1031. UU.log(nonLatins);
  1032. UU.log(blacklist);
  1033. UU.log(hiddenList);
  1034.  
  1035. const _VM = (typeof VM !== 'undefined' ? VM : null) || {
  1036. shortcut: {
  1037. register: () => { }
  1038. }
  1039. };
  1040.  
  1041.  
  1042. function fixLibraryCodeURL(code_url) {
  1043. if (/\/scripts\/(\d+)(\-[^\/]+)\/code\//.test(code_url)) {
  1044. code_url = code_url.replace(/\/scripts\/(\d+)(\-[^\/]+)\/code\//, '/scripts/$1/code/');
  1045. let qm = code_url.indexOf('?');
  1046. let s1 = code_url.substring(0, qm);
  1047. let s2 = code_url.substring(qm + 1);
  1048. if (qm > 0) {
  1049. code_url = `${decodeURI(s1)}?${s2}`;
  1050. }
  1051. }
  1052. return code_url;
  1053. }
  1054.  
  1055. function setClickToSelect(elm) {
  1056. elm.addEventListener('click', function () {
  1057. if (window.getSelection() + "" === "") {
  1058. if (typeof this.select === 'function') {
  1059. this.select();
  1060. } else {
  1061. const range = document.createRange(); // Create a range object
  1062. range.selectNode(this); // Select the text within the element
  1063. const selection = window.getSelection(); // Get the selection object
  1064. selection.removeAllRanges(); // First clear any existing selections
  1065. selection.addRange(range); // Add the new range to the selection
  1066. }
  1067. }
  1068. });
  1069. elm.addEventListener('drag', function (evt) {
  1070. evt.preventDefault();
  1071. });
  1072. elm.addEventListener('drop', function (evt) {
  1073. evt.preventDefault();
  1074. });
  1075. elm.addEventListener('dragstart', function (evt) {
  1076. evt.preventDefault();
  1077. });
  1078. }
  1079.  
  1080. const copyText = typeof (((window.navigator || 0).clipboard || 0).writeText) === 'function' ? (text) => {
  1081. navigator.clipboard.writeText(text).then(function () {
  1082. //
  1083. }).catch(function (err) {
  1084. alert("Unable to Copy");
  1085. });
  1086. } : (text) => {
  1087. const textToCopy = document.createElement('strong');
  1088. textToCopy.style.position = 'fixed';
  1089. textToCopy.style.opacity = '0';
  1090. textToCopy.style.top = '-900vh';
  1091. textToCopy.textContent = text;
  1092. document.body.appendChild(textToCopy);
  1093.  
  1094. const range = document.createRange(); // Create a range object
  1095. range.selectNode(textToCopy); // Select the text within the element
  1096.  
  1097. const selection = window.getSelection(); // Get the selection object
  1098. selection.removeAllRanges(); // First clear any existing selections
  1099. selection.addRange(range); // Add the new range to the selection
  1100.  
  1101. try {
  1102. document.execCommand('copy'); // Try to copy the selected text
  1103. } catch (err) {
  1104. alert("Unable to Copy");
  1105. }
  1106.  
  1107. selection.removeAllRanges(); // Remove the selection range after copying
  1108. textToCopy.remove();
  1109. };
  1110.  
  1111.  
  1112. let avoidDuplication = 0;
  1113. const avoidDuplicationF = () => {
  1114. const p = avoidDuplication;
  1115. avoidDuplication = Date.now();
  1116. if (avoidDuplication - p < 30) return false;
  1117. return true;
  1118. }
  1119. // https://violentmonkey.github.io/vm-shortcut/
  1120. const shortcuts = [
  1121. ['ctrlcmd-alt-keys', () => avoidDuplicationF() && gmc.open()],
  1122. ['ctrlcmd-alt-keyb', () => avoidDuplicationF() && toggleListDisplayingItem('blacklisted')],
  1123. ['ctrlcmd-alt-keyh', () => avoidDuplicationF() && toggleListDisplayingItem('hidden')]
  1124. ]
  1125. for (const [scKey, scFn] of shortcuts) {
  1126. _VM.shortcut.register(scKey, scFn);
  1127. }
  1128.  
  1129. const addSettingsToMenu = () => {
  1130. const nav = document.querySelector('#site-nav > nav')
  1131. if (!nav) return;
  1132.  
  1133. const scriptName = GM.info.script.name;
  1134. const scriptVersion = GM.info.script.version;
  1135. const menu = document.createElement('li');
  1136. menu.classList.add(id);
  1137. menu.setAttribute('alt', `${scriptName} ${scriptVersion}`);
  1138. menu.setAttribute('title', `${scriptName} ${scriptVersion}`);
  1139. const link = document.createElement('a');
  1140. link.setAttribute('href', '#');
  1141. link.textContent = GM.info.script.name;
  1142. menu.appendChild(link);
  1143. nav.insertBefore(menu, document.querySelector('#site-nav > nav > li:first-of-type'));
  1144.  
  1145. menu.addEventListener('click', (e) => {
  1146. e.preventDefault();
  1147. e.stopPropagation();
  1148. e.stopImmediatePropagation();
  1149. gmc.open();
  1150. });
  1151. };
  1152.  
  1153.  
  1154. const toggleListDisplayingItem = (t) => {
  1155.  
  1156. const m = document.documentElement;
  1157.  
  1158. const p = t + '-shown';
  1159. let currentIsShown = m.hasAttribute(p)
  1160. if (!currentIsShown) {
  1161. m.setAttribute(p, '')
  1162. } else {
  1163. m.removeAttribute(p)
  1164. }
  1165.  
  1166. }
  1167.  
  1168. const createListOptionGroup = () => {
  1169.  
  1170. const html = `<div class="list-option-group" id="${id}-options">${GM.info.script.name} Lists:<ul>
  1171. <li class="list-option blacklisted"><a href="#" id="hyperlink-35389"></a></li>
  1172. <li class="list-option hidden"><a href="#" id="hyperlink-40361"></a></li>
  1173. </ul></div>`;
  1174. const firstOptionGroup = document.querySelector('.list-option-groups > div');
  1175. firstOptionGroup && firstOptionGroup.insertAdjacentHTML('beforebegin', html);
  1176.  
  1177. const blacklistedOption = document.querySelector(`#${id}-options li.blacklisted`);
  1178. blacklistedOption && blacklistedOption.addEventListener('click', (evt) => {
  1179. evt.preventDefault();
  1180. toggleListDisplayingItem('blacklisted');
  1181. }, false);
  1182.  
  1183. const hiddenOption = document.querySelector(`#${id}-options li.hidden`);
  1184. hiddenOption && hiddenOption.addEventListener('click', (evt) => {
  1185. evt.preventDefault();
  1186. toggleListDisplayingItem('hidden');
  1187. }, false);
  1188.  
  1189. }
  1190.  
  1191. const addOptions = () => {
  1192.  
  1193. const gn = () => {
  1194.  
  1195. let aBlackList = document.querySelector('#hyperlink-35389');
  1196. let aHidden = document.querySelector('#hyperlink-40361');
  1197. if (!aBlackList || !aHidden) return;
  1198. aBlackList.textContent = `Blacklisted scripts (${document.querySelectorAll('.script-list li.blacklisted').length})`;
  1199. aHidden.textContent = `Hidden scripts (${document.querySelectorAll('.script-list li.hidden').length})`
  1200.  
  1201. }
  1202. const callback = (entries) => {
  1203. if (entries && entries.length >= 1) requestAnimationFrame(gn);
  1204. }
  1205.  
  1206. const setupScriptList = async () => {
  1207. let scriptList;
  1208. let i = 8;
  1209. while (i-- > 0) {
  1210. scriptList = document.querySelector('.script-list li')
  1211. if (scriptList) scriptList = scriptList.closest('.script-list')
  1212. if (scriptList) break;
  1213. await new Promise(r => requestAnimationFrame(r))
  1214. }
  1215. if (!scriptList) return;
  1216. createListOptionGroup();
  1217. const mo = new MutationObserver(callback);
  1218. mo.observe(scriptList, { childList: true, subtree: true });
  1219. gn();
  1220. }
  1221. setupScriptList();
  1222.  
  1223. };
  1224.  
  1225.  
  1226. /**
  1227. * Get script data from Greasy Fork API
  1228. *
  1229. * @param {number} id Script ID
  1230. * @returns {Promise} Script data
  1231. */
  1232. let networkMP1 = Promise.resolve();
  1233. let networkMP2 = Promise.resolve();
  1234. let previousIsCache = false;
  1235. // let ss = [];
  1236. // var sum = function(nums) {
  1237. // var total = 0;
  1238. // for (var i = 0, len = nums.length; i < len; i++) total += nums[i];
  1239. // return total;
  1240. // };
  1241. const getScriptData = async (id, noCache) => {
  1242. if (!(id >= 0)) return Promise.resolve()
  1243. const url = `https://${window.location.hostname}/scripts/${id}.json`;
  1244. return new Promise((resolve, reject) => {
  1245.  
  1246. networkMP1 = networkMP1.then(() => new Promise(unlock => {
  1247.  
  1248. const maxAgeInSeconds = 900;
  1249. const rd = previousIsCache ? 1 : Math.floor(Math.random() * 80 + 80);
  1250. let fetchStart = 0;
  1251. new Promise(r => setTimeout(r, rd))
  1252. .then(() => {
  1253. fetchStart = Date.now();
  1254. })
  1255. .then(() => fetch(url, noCache ? {
  1256. method: 'GET',
  1257. cache: 'reload',
  1258. credentials: 'omit',
  1259. headers: new Headers({
  1260. 'Cache-Control': `max-age=${maxAgeInSeconds}`,
  1261. })
  1262. } : {
  1263. method: 'GET',
  1264. cache: 'force-cache',
  1265. credentials: 'omit',
  1266. headers: new Headers({
  1267. 'Cache-Control': `max-age=${maxAgeInSeconds}`,
  1268. }),
  1269. }))
  1270. .then((response) => {
  1271.  
  1272. let fetchStop = Date.now();
  1273. // const dd = fetchStop - fetchStart;
  1274. // dd (cache) = {min: 1, max: 8, avg: 3.7}
  1275. // dd (normal) = {min: 136, max: 316, avg: 162.62}
  1276.  
  1277. // ss.push(dd)
  1278. // ss.maxValue = Math.max(...ss);
  1279. // ss.minValue = Math.min(...ss);
  1280. // ss.avgValue = sum(ss)/ss.length;
  1281. // console.log(dd)
  1282. // console.log(ss)
  1283. previousIsCache = (fetchStop - fetchStart) < (3.7 + 162.62) / 2;
  1284. UU.log(`${response.status}: ${response.url}`)
  1285. // UU.log(response)
  1286. if (response.ok === true) {
  1287. unlock();
  1288. return response.json()
  1289. }
  1290. if (response.status === 503) {
  1291. return new Promise(r => setTimeout(r, 270 + rd)).then(() => {
  1292. unlock();
  1293. return getScriptData(id, true);
  1294. });
  1295. }
  1296. if (response.status === 404) {
  1297. // script XXXX has been reported and is pending review by a moderator.
  1298. unlock();
  1299. return null
  1300. }
  1301. console.warn(response.status, response);
  1302. new Promise(r => setTimeout(r, 470)).then(unlock); // reload later
  1303. })
  1304. .then((data) => resolve(data))
  1305. .catch((e) => {
  1306. unlock();
  1307. UU.log(id, url)
  1308. console.warn(e)
  1309. // reject(e)
  1310. })
  1311.  
  1312. })).catch(() => { })
  1313.  
  1314. });
  1315. }
  1316.  
  1317. /**
  1318. * Get user data from Greasy Fork API
  1319. *
  1320. * @param {string} userID User ID
  1321. * @returns {Promise} User data
  1322. */
  1323. const getUserData = (userID, noCache) => {
  1324.  
  1325. if (!(userID >= 0)) return Promise.resolve()
  1326.  
  1327. const url = `https://${window.location.hostname}/users/${userID}.json`;
  1328. return new Promise((resolve, reject) => {
  1329.  
  1330.  
  1331. networkMP2 = networkMP2.then(() => new Promise(unlock => {
  1332.  
  1333. const maxAgeInSeconds = 900;
  1334. const rd = Math.floor(Math.random() * 80 + 80);
  1335.  
  1336. new Promise(r => setTimeout(r, rd))
  1337. .then(() => fetch(url, noCache ? {
  1338. method: 'GET',
  1339. cache: 'reload',
  1340. credentials: 'omit',
  1341. headers: new Headers({
  1342. 'Cache-Control': `max-age=${maxAgeInSeconds}`,
  1343. })
  1344. } : {
  1345. method: 'GET',
  1346. cache: 'force-cache',
  1347. credentials: 'omit',
  1348. headers: new Headers({
  1349. 'Cache-Control': `max-age=${maxAgeInSeconds}`,
  1350. }),
  1351. }))
  1352. .then((response) => {
  1353. UU.log(`${response.status}: ${response.url}`)
  1354. if (response.ok === true) {
  1355. unlock();
  1356. return response.json()
  1357. }
  1358. if (response.status === 503) {
  1359. return new Promise(r => setTimeout(r, 270 + rd)).then(() => {
  1360. unlock();
  1361. return getUserData(userID, true); // reload later
  1362. });
  1363. }
  1364. if (response.status === 404) {
  1365. // user XXXX has been reported and is pending review by a moderator. ????
  1366. unlock();
  1367. return null
  1368. }
  1369. console.warn(response.status, response);
  1370. new Promise(r => setTimeout(r, 470)).then(unlock);
  1371. })
  1372. .then((data) => resolve(data))
  1373. .catch((e) => {
  1374. setTimeout(() => {
  1375. unlock()
  1376. }, 270)
  1377. UU.log(userID, url)
  1378. console.warn(e)
  1379. // reject(e)
  1380. })
  1381.  
  1382.  
  1383.  
  1384. })).catch(() => { })
  1385.  
  1386. });
  1387. }
  1388. const getTotalInstalls = (data) => {
  1389. if (!data || !data.scripts) return;
  1390. return new Promise((resolve, reject) => {
  1391. const totalInstalls = [];
  1392.  
  1393. data.scripts.forEach((element) => {
  1394. totalInstalls.push(parseInt(element.total_installs, 10));
  1395. });
  1396.  
  1397. resolve(totalInstalls.reduce((a, b) => a + b, 0));
  1398. });
  1399. };
  1400.  
  1401.  
  1402. const communicationId = WinComm.newCommunicationId();
  1403. const wincomm = WinComm.createInstance(communicationId);
  1404.  
  1405.  
  1406. const isInstalled = (script) => {
  1407. return new Promise((resolve, reject) => {
  1408.  
  1409. promiseScriptCheck.then(d => {
  1410.  
  1411. if (!d) return null;
  1412.  
  1413. const data = d.data;
  1414. const al = data.type % 10;
  1415. if (al === 0) {
  1416. // no namespace
  1417. resolve([null, script.name, '']);
  1418. } else if (al === 1) {
  1419. // namespace
  1420.  
  1421. if (!script.namespace) {
  1422.  
  1423. getScriptData(script.id).then((script) => {
  1424. resolve([null, script.name, script.namespace]);
  1425. });
  1426.  
  1427. } else {
  1428.  
  1429. resolve([null, script.name, script.namespace]);
  1430. }
  1431.  
  1432. }
  1433.  
  1434.  
  1435. })
  1436.  
  1437.  
  1438. }).then((res) => {
  1439.  
  1440.  
  1441. return new Promise((resolve, reject) => {
  1442.  
  1443. if (!res) return '';
  1444.  
  1445.  
  1446. const [_, name, namespace] = res;
  1447. wincomm.request('installedVersion.req', {
  1448. name,
  1449. namespace
  1450. }).then(d => {
  1451. resolve(d.data.version)
  1452. })
  1453.  
  1454. })
  1455.  
  1456. })
  1457.  
  1458. /*
  1459. const external = unsafeWindow.external;
  1460. const scriptHandler = GM.info.scriptHandler;
  1461. if (external && external.Violentmonkey && (scriptHandler || 'Violentmonkey') === 'Violentmonkey') {
  1462. external.Violentmonkey.isInstalled(name, namespace).then((data) => resolve(data));
  1463. return;
  1464. }
  1465.  
  1466. if (external && external.Tampermonkey && (scriptHandler || 'Tampermonkey') === 'Tampermonkey') {
  1467. external.Tampermonkey.isInstalled(name, namespace, (data) => {
  1468. (data.installed) ? resolve(data.version) : resolve();
  1469. });
  1470. return;
  1471. }
  1472. */
  1473.  
  1474.  
  1475. };
  1476.  
  1477. const compareVersions = (v1, v2) => {
  1478. if (!v1 || !v2) return NaN;
  1479. if (v1 === null || v2 === null) return NaN;
  1480. if (v1 === v2) return 0;
  1481.  
  1482. const sv1 = v1.split('.').map((index) => parseInt(index));
  1483. const sv2 = v2.split('.').map((index) => parseInt(index));
  1484.  
  1485. for (let index = 0; index < Math.max(sv1.length, sv2.length); index++) {
  1486. if (isNaN(sv1[index]) || isNaN(sv2[index])) return NaN;
  1487. if (sv1[index] > sv2[index]) return 1;
  1488. if (sv1[index] < sv2[index]) return -1;
  1489. }
  1490.  
  1491. return 0;
  1492. };
  1493.  
  1494.  
  1495. /**
  1496. * Return label for the hide script button
  1497. *
  1498. * @param {boolean} hidden Is hidden
  1499. * @returns {string} Label
  1500. */
  1501. const blockLabel = (hidden) => {
  1502. return hidden ? (locales[lang] ? locales[lang].notHide : locales.en.notHide) : (locales[lang] ? locales[lang].hide : locales.en.hide)
  1503. }
  1504.  
  1505. /**
  1506. * Return label for the install button
  1507. *
  1508. * @param {number} update Update value
  1509. * @returns {string} Label
  1510. */
  1511. const installLabel = (update) => {
  1512. switch (update) {
  1513. case 0: {
  1514. return locales[lang] ? locales[lang].reinstall : locales.en.reinstall
  1515. }
  1516. case 1: {
  1517. return locales[lang] ? locales[lang].update : locales.en.update
  1518. }
  1519. case -1: {
  1520. return locales[lang] ? locales[lang].downgrade : locales.en.downgrade
  1521. }
  1522. default: {
  1523. return locales[lang] ? locales[lang].install : locales.en.install
  1524. }
  1525. }
  1526. }
  1527.  
  1528. const hideBlacklistedScript = (element, list) => {
  1529. if (!element) return;
  1530. const scriptLink = element.querySelector('.script-link')
  1531.  
  1532. const name = scriptLink ? scriptLink.textContent : '';
  1533. const descriptionElem = element.querySelector('.script-description')
  1534. const description = descriptionElem ? descriptionElem.textContent : '';
  1535.  
  1536. if (!name) return;
  1537.  
  1538. switch (list) {
  1539. case 'nonLatins':
  1540. if ((nonLatins.test(name) || nonLatins.test(description)) && !element.classList.contains('blacklisted')) {
  1541. element.classList.add('blacklisted', 'non-latins');
  1542. if (gmc.get('hideBlacklistedScripts') && gmc.get('debugging')) {
  1543. let scriptLink = element.querySelector('.script-link');
  1544. if (scriptLink) { scriptLink.textContent += ' (non-latin)'; }
  1545. }
  1546. }
  1547. break;
  1548. case 'blacklist':
  1549. if (isBlackList(name, description) && !element.classList.contains('blacklisted')) {
  1550. element.classList.add('blacklisted', 'blacklist');
  1551. if (gmc.get('hideBlacklistedScripts') && gmc.get('debugging')) {
  1552. let scriptLink = element.querySelector('.script-link');
  1553. if (scriptLink) { scriptLink.textContent += ' (blacklist)'; }
  1554. }
  1555. }
  1556. break;
  1557. case 'customBlacklist': {
  1558. const customBlacklist = customBlacklistRE;
  1559. if (customBlacklist && (customBlacklist.test(name) || customBlacklist.test(description)) && !element.classList.contains('blacklisted')) {
  1560. element.classList.add('blacklisted', 'custom-blacklist');
  1561. if (gmc.get('hideBlacklistedScripts') && gmc.get('debugging')) {
  1562. let scriptLink = element.querySelector('.script-link');
  1563. if (scriptLink) { scriptLink.textContent += ' (custom-blacklist)'; }
  1564. }
  1565. }
  1566. break;
  1567. }
  1568. default:
  1569. UU.log('No blacklists');
  1570. break;
  1571. }
  1572. };
  1573.  
  1574. const hideHiddenScript = (element, id, list) => {
  1575. id = +id;
  1576. if (!(id >= 0)) return;
  1577.  
  1578. const isInHiddenList = () => hiddenList.indexOf(id) !== -1;
  1579. const updateScriptLink = (shouldHide) => {
  1580. if (gmc.get('hideHiddenScript') && gmc.get('debugging')) {
  1581. let scriptLink = element.querySelector('.script-link');
  1582. if (scriptLink) {
  1583. if (shouldHide) {
  1584. scriptLink.innerHTML += ' (hidden)';
  1585. } else {
  1586. scriptLink.innerHTML = scriptLink.innerHTML.replace(' (hidden)', '');
  1587. }
  1588. }
  1589. }
  1590. };
  1591.  
  1592. // Check for initial state and set it
  1593. if (isInHiddenList()) {
  1594. element.classList.add('hidden');
  1595. updateScriptLink(true);
  1596. }
  1597.  
  1598. // Add button to hide the script
  1599. const insertButtonHTML = (selector, html) => {
  1600. const target = element.querySelector(selector);
  1601. if (!target) return;
  1602. let p = document.createElement('template');
  1603. p.innerHTML = html;
  1604. target.parentNode.insertBefore(p.content.firstChild, target.nextSibling);
  1605. };
  1606.  
  1607. const isHidden = element.classList.contains('hidden');
  1608. const blockButtonHTML = `<span class=block-button role=button style-16377>${blockLabel(isHidden)}</span>`;
  1609. const blockButtonHeaderHTML = `<span class=block-button role=button style-77329 style="">${blockLabel(isHidden)}</span>`;
  1610.  
  1611. insertButtonHTML('.badge-js, .badge-css', blockButtonHTML);
  1612. insertButtonHTML('header h2', blockButtonHeaderHTML);
  1613.  
  1614. // Add event listener
  1615. const button = element.querySelector('.block-button');
  1616. if (button) {
  1617. button.addEventListener('click', (event) => {
  1618. event.stopPropagation();
  1619. event.stopImmediatePropagation();
  1620.  
  1621. if (!isInHiddenList()) {
  1622. hiddenList.push(id);
  1623. GM.setValue('hiddenList', hiddenList);
  1624.  
  1625. element.classList.add('hidden');
  1626. updateScriptLink(true);
  1627.  
  1628. } else {
  1629. const index = hiddenList.indexOf(id);
  1630. hiddenList.splice(index, 1);
  1631. GM.setValue('hiddenList', hiddenList);
  1632.  
  1633. element.classList.remove('hidden');
  1634. updateScriptLink(false);
  1635. }
  1636.  
  1637. const blockBtn = element.querySelector('.block-button');
  1638. if (blockBtn) blockBtn.textContent = blockLabel(element.classList.contains('hidden'));
  1639. });
  1640. }
  1641. };
  1642.  
  1643. const insertButtonHTML = (element, selector, html) => {
  1644. const target = element.querySelector(selector);
  1645. if (!target) return;
  1646. let p = document.createElement('template');
  1647. p.innerHTML = html;
  1648. let button = p.content.firstChild
  1649. target.parentNode.insertBefore(button, target.nextSibling);
  1650. return button;
  1651. };
  1652.  
  1653. const addInstallButton = (element, url) => {
  1654. return setupInstallLink(insertButtonHTML(element, '.badge-js, .badge-css', `<a class="install-link" href="${url}" style-54998></a>`));
  1655. };
  1656.  
  1657. async function digestMessage(message, algo) {
  1658. const encoder = new TextEncoder();
  1659. const data = encoder.encode(message);
  1660. const hash = await crypto.subtle.digest(algo, data);
  1661. return hash;
  1662. }
  1663.  
  1664. function qexString(buffer) {
  1665. const byteArray = new Uint8Array(buffer);
  1666. const len = byteArray.length;
  1667. const hexCodes = new Array(len * 2);
  1668. const chars = 'a4b3c5d7e6f9h2t';
  1669. for (let i = 0, j = 0; i < len; i++) {
  1670. const byte = byteArray[i];
  1671. hexCodes[j++] = chars[byte >> 4];
  1672. hexCodes[j++] = chars[byte & 0x0F];
  1673. };
  1674. return hexCodes.join('');
  1675. }
  1676.  
  1677. const encodeFileName = (s) => {
  1678. if (!s || typeof s !== 'string') return s;
  1679. s = s.replace(/[.!~*'"();\/\\?@&=$,#]/g, '-').replace(/\s+/g, ' ');
  1680. return encodeURI(s);
  1681. }
  1682.  
  1683. const isLibraryURLWithVersion = (url) => {
  1684. if (!url || typeof url !== 'string') return;
  1685.  
  1686. if (url.includes('.js?version=')) return true;
  1687.  
  1688. if (/\/scripts\/\d+\/\d+\/[^.!~*'"();\/\\?@&=$,#]+\.js/.test(url)) return true;
  1689. return false;
  1690.  
  1691. }
  1692.  
  1693. const showInstallButton = async (scriptID, element) => {
  1694.  
  1695. // if(document.querySelector(`li[data-script-id="${scriptID}"]`))
  1696. let _baseScript = null;
  1697. if (element.nodeName === 'LI' && element.hasAttribute('data-script-id') && element.getAttribute('data-script-id') === `${scriptID}` && element.getAttribute('data-script-language') === 'js') {
  1698.  
  1699. const version = element.getAttribute('data-script-version') || ''
  1700.  
  1701. let scriptCodeURL = element.getAttribute('data-code-url');
  1702. if (!scriptCodeURL || !isVaildURL(scriptCodeURL)) {
  1703.  
  1704. const name = element.getAttribute('data-script-name') || ''
  1705. // if (!/[^\x00-\x7F]/.test(name)) {
  1706.  
  1707. // const scriptName = useHashedScriptName ? qexString(await digestMessage(`${+scriptID} ${version}`, 'SHA-1')).substring(0, 8) : encodeURI(name);
  1708. // const token = useHashedScriptName ? `${scriptName.substring(0, 2)}${scriptName.substring(scriptName.length - 2, scriptName.length)}` : String.fromCharCode(Date.now() % 26 + 97) + Math.floor(Math.random() * 19861 + 19861).toString(36);
  1709. const scriptFilename = element.getAttribute('data-script-type') === 'library' ? `${encodeFileName(name)}.js` : `${encodeFileName(name)}.user.js`;
  1710. // const scriptFilename = `${scriptName}.user.js`;
  1711.  
  1712. // code_url: `https://${location.hostname}/scripts/${scriptID}-${token}/code/${scriptFilename}`,
  1713. // code_url: `https://update.${location.hostname}/scripts/${scriptID}.user.js`,
  1714. scriptCodeURL = `https://update.${location.hostname}/scripts/${scriptID}/${scriptFilename}`
  1715. }
  1716. _baseScript = {
  1717. id: +scriptID,
  1718. // name: name,
  1719. code_url: scriptCodeURL,
  1720. version: version
  1721. }
  1722. // }
  1723.  
  1724. }
  1725.  
  1726. const baseScript = _baseScript || (await getScriptData(scriptID));
  1727.  
  1728. if ((element.nodeName === 'LI' && element.getAttribute('data-script-type') === 'library') || (baseScript.code_url.includes('.js?version='))) {
  1729.  
  1730. let scriptCodeURL = element.getAttribute('data-code-url');
  1731.  
  1732. if (!scriptCodeURL || !isVaildURL(scriptCodeURL)) {
  1733. const script = baseScript.code_url.includes('.js?version=') ? baseScript : (await getScriptData(scriptID));
  1734. scriptCodeURL = script.code_url;
  1735. }
  1736.  
  1737. if (scriptCodeURL && isLibraryURLWithVersion(scriptCodeURL)) {
  1738.  
  1739.  
  1740. const code_url = fixLibraryCodeURL(scriptCodeURL);
  1741.  
  1742. const button = addInstallButton(element, code_url);
  1743. button.textContent = `Copy URL`;
  1744. button.addEventListener('click', function (evt) {
  1745.  
  1746. const target = (evt || 0).target;
  1747. if (!target) return;
  1748.  
  1749. let a = target.nodeName === 'A' ? target : target.querySelector('a[href]');
  1750.  
  1751. if (!a) return;
  1752. let href = target.getAttribute('href');
  1753. if (!href) return;
  1754.  
  1755. evt.preventDefault();
  1756.  
  1757. copyText(href);
  1758.  
  1759.  
  1760. });
  1761.  
  1762. }
  1763.  
  1764.  
  1765. } else {
  1766.  
  1767.  
  1768. if (!baseScript || !baseScript.code_url || !baseScript.version) return;
  1769. const button = addInstallButton(element, baseScript.code_url);
  1770. button.classList.add('install-status-checking');
  1771. button.textContent = `${installLabel()} ${baseScript.version}`;
  1772. const script = baseScript && baseScript.name && baseScript.namespace ? baseScript : (await getScriptData(scriptID));
  1773. if (!script) return;
  1774.  
  1775. const installed = await isInstalled(script);
  1776. const version = (
  1777. baseScript.version && script.version && compareVersions(baseScript.version, script.version) === 1
  1778. ) ? baseScript.version : script.version;
  1779.  
  1780. const update = compareVersions(version, installed); // NaN 1 -1 0
  1781. const label = installLabel(update);
  1782. button.textContent = `${label} ${version}`;
  1783. button.classList.remove('install-status-checking');
  1784.  
  1785.  
  1786. }
  1787.  
  1788. }
  1789.  
  1790.  
  1791. const foundScriptList = async (scriptList) => {
  1792.  
  1793. let rid = 0;
  1794. let g = () => {
  1795. if (!scriptList || scriptList.isConnected !== true) return;
  1796.  
  1797. const scriptElements = scriptList.querySelectorAll('li[data-script-id]:not([e8kk])');
  1798.  
  1799. for (const element of scriptElements) {
  1800. element.setAttribute('e8kk', '1');
  1801.  
  1802. const scriptID = +element.getAttribute('data-script-id');
  1803. if (!(scriptID > 0)) continue;
  1804.  
  1805. // blacklisted scripts
  1806. if (gmc.get('nonLatins')) hideBlacklistedScript(element, 'nonLatins');
  1807. if (gmc.get('blacklist')) hideBlacklistedScript(element, 'blacklist');
  1808. if (gmc.get('customBlacklist')) hideBlacklistedScript(element, 'customBlacklist');
  1809.  
  1810. // hidden scripts
  1811. if (gmc.get('hideHiddenScript')) hideHiddenScript(element, scriptID, true);
  1812.  
  1813. // install button
  1814. if (gmc.get('showInstallButton')) {
  1815. showInstallButton(scriptID, element)
  1816. }
  1817. }
  1818.  
  1819. }
  1820. let f = (entries) => {
  1821. const tid = ++rid
  1822. if (entries && entries.length) requestAnimationFrame(() => {
  1823. if (tid === rid) g();
  1824. });
  1825. }
  1826. let mo = new MutationObserver(f);
  1827. mo.observe(scriptList, { subtree: true, childList: true });
  1828.  
  1829. g();
  1830.  
  1831. }
  1832.  
  1833. let promiseScriptCheckResolve = null;
  1834. const promiseScriptCheck = new Promise(resolve => {
  1835. promiseScriptCheckResolve = resolve
  1836. });
  1837.  
  1838. const milestoneNotificationFn = async (o) => {
  1839.  
  1840. const { userLink, userID } = o;
  1841.  
  1842.  
  1843. const milestones = gmc.get('milestoneNotification').replace(/\s/g, '').split(',').map(Number);
  1844.  
  1845. if (!userID) return;
  1846.  
  1847. const userData = await getUserData(+userID.match(/\d+(?=\D)/g));
  1848. if (!userData) return;
  1849.  
  1850. const [totalInstalls, lastMilestone] = await Promise.all([
  1851. getTotalInstalls(userData),
  1852. GM.getValue('lastMilestone', 0)]);
  1853.  
  1854. const milestone = milestones.filter(milestone => totalInstalls >= milestone).pop();
  1855.  
  1856. UU.log(`total installs are "${totalInstalls}", milestone reached is "${milestone}", last milestone reached is "${lastMilestone}"`);
  1857.  
  1858. if (milestone <= lastMilestone) return;
  1859.  
  1860. if (milestone && milestone >= 0) {
  1861.  
  1862.  
  1863. GM.setValue('lastMilestone', milestone);
  1864.  
  1865. const lang = document.documentElement.lang;
  1866. const text = (locales[lang] ? locales[lang].milestone : locales.en.milestone).replace('$1', milestone.toLocaleString());
  1867.  
  1868. if (typeof GM.notification === 'function') {
  1869. GM.notification({
  1870. text,
  1871. title: GM.info.script.name,
  1872. image: logo,
  1873. onclick: () => {
  1874. window.location = `https://${window.location.hostname}${userID}#user-script-list-section`;
  1875. }
  1876. });
  1877. } else {
  1878. UU.alert(text);
  1879. }
  1880.  
  1881. }
  1882.  
  1883. }
  1884. const onReady = async () => {
  1885.  
  1886. try {
  1887.  
  1888. const gminfo = GM.info || 0;
  1889. if (gminfo) {
  1890.  
  1891. const gminfoscript = gminfo.script || 0;
  1892.  
  1893.  
  1894. const scriptHandlerObject = {
  1895. scriptHandler: gminfo.scriptHandler || '',
  1896. scriptName: gminfoscript.name || '', // not name_i18n
  1897. scriptVersion: gminfoscript.version || '',
  1898. scriptNamespace: gminfoscript.namespace || '',
  1899. communicationId
  1900. };
  1901.  
  1902.  
  1903. wincomm.hook('_$GreasyFork$Msg$OnScriptInstallFeedback',
  1904. {
  1905.  
  1906. ready: (d, evt) => promiseScriptCheckResolve(d),
  1907. userScriptManagerNotDetected: (d, evt) => promiseScriptCheckResolve(null),
  1908. 'installedVersion.res': wincomm.handleResponse
  1909.  
  1910.  
  1911. })
  1912.  
  1913.  
  1914. document.head.appendChild(document.createElement('script')).textContent = `;(${mWindow.contentScriptText})(${JSON.stringify(scriptHandlerObject)}, ${WinComm.createInstance});`;
  1915.  
  1916.  
  1917. }
  1918.  
  1919.  
  1920. addSettingsToMenu();
  1921.  
  1922.  
  1923. setTimeout(() => {
  1924. let installBtn = document.querySelector('a[data-script-id][data-script-version]')
  1925. let scriptID = installBtn && installBtn.textContent ? +installBtn.getAttribute('data-script-id') : 0;
  1926. if (scriptID > 0) {
  1927. getScriptData(scriptID, true);
  1928. } else {
  1929.  
  1930.  
  1931. const userLink = document.querySelector('#site-nav .user-profile-link a[href]');
  1932. let userID = userLink ? userLink.getAttribute('href') : '';
  1933.  
  1934. userID = userID ? /users\/(\d+)/.exec(userID) : null;
  1935. if (userID) userID = userID[1];
  1936. if (userID) {
  1937. userID = +userID;
  1938. if (userID > 0) {
  1939. getUserData(userID, true);
  1940. }
  1941. }
  1942.  
  1943.  
  1944. }
  1945. }, 740);
  1946.  
  1947. const userLink = document.querySelector('.user-profile-link a[href]');
  1948. const userID = userLink ? userLink.getAttribute('href') : undefined;
  1949.  
  1950. UU.addStyle(mWindow.pageCSS);
  1951. // blacklisted scripts / hidden scripts / install button
  1952. if (window.location.pathname !== userID && !/discussions/.test(window.location.pathname) && (gmc.get('hideBlacklistedScripts') || gmc.get('hideHiddenScript') || gmc.get('showInstallButton'))) {
  1953.  
  1954. const scriptList = document.querySelector('.script-list');
  1955. if (scriptList) {
  1956. foundScriptList(scriptList);
  1957. } else {
  1958. const timeout = Date.now() + 3000;
  1959. /** @type {MutationObserver | null} */
  1960. let mo = null;
  1961. const mutationCallbackForScriptList = () => {
  1962. if (!mo) return;
  1963. const scriptList = document.querySelector('.script-list');
  1964. if (scriptList) {
  1965. mo.disconnect();
  1966. mo.takeRecords();
  1967. mo = null;
  1968. foundScriptList(scriptList);
  1969. } else if (Date.now() > timeout) {
  1970. mo.disconnect();
  1971. mo.takeRecords();
  1972. mo = null;
  1973. }
  1974. }
  1975. mo = new MutationObserver(mutationCallbackForScriptList);
  1976. mo.observe(document, { subtree: true, childList: true });
  1977. }
  1978.  
  1979.  
  1980. // hidden scripts on details page
  1981. const installLinkElement = document.querySelector('#script-info .install-link[data-script-id]');
  1982. setupInstallLink(installLinkElement);
  1983. if (gmc.get('hideHiddenScript') && installLinkElement) {
  1984. const id = +installLinkElement.getAttribute('data-script-id');
  1985. hideHiddenScript(document.querySelector('#script-info'), id, false);
  1986. }
  1987.  
  1988. // add options and style for blacklisted/hidden scripts
  1989. if (gmc.get('hideBlacklistedScripts') || gmc.get('hideHiddenScript')) {
  1990. addOptions();
  1991. }
  1992.  
  1993. if (installLinkElement && location.pathname.includes('/scripts/')) {
  1994.  
  1995. installLinkElement.addEventListener('click', async function (e) {
  1996. if (e && e.isTrusted && location.pathname.includes('/scripts/')) {
  1997.  
  1998. await new Promise(r => setTimeout(r, 800));
  1999. await new Promise(r => window.requestAnimationFrame(r));
  2000. await new Promise(r => setTimeout(r, 100));
  2001. document.dispatchEvent(new Event("DOMContentLoaded"));
  2002. }
  2003. })
  2004. }
  2005. }
  2006.  
  2007. // total installs
  2008. if (gmc.get('showTotalInstalls') && document.querySelector('#user-script-list')) {
  2009. const dailyInstalls = [];
  2010. const totalInstalls = [];
  2011.  
  2012. const dailyInstallElements = document.querySelectorAll('#user-script-list li dd.script-list-daily-installs');
  2013. for (const element of dailyInstallElements) {
  2014. dailyInstalls.push(parseInt(element.textContent.replace(/\D/g, ''), 10));
  2015. }
  2016.  
  2017. const totalInstallElements = document.querySelectorAll('#user-script-list li dd.script-list-total-installs');
  2018. for (const element of totalInstallElements) {
  2019. totalInstalls.push(parseInt(element.textContent.replace(/\D/g, ''), 10));
  2020. }
  2021.  
  2022. const dailyInstallsSum = dailyInstalls.reduce((a, b) => a + b, 0);
  2023. const totalInstallsSum = totalInstalls.reduce((a, b) => a + b, 0);
  2024.  
  2025. const convertLi = (li) => {
  2026.  
  2027. if (!li) return null;
  2028. const a = li.firstElementChild
  2029. if (a === null) return li;
  2030. if (a === li.lastElementChild && a.nodeName === 'A') return a;
  2031.  
  2032.  
  2033. return null;
  2034. }
  2035.  
  2036. const plusSign = document.querySelector('#user-script-list-section a[rel="next"][href*="page="], #user-script-list-section a[rel="prev"][href*="page="]') ? '+' : '';
  2037.  
  2038. const dailyOption = convertLi(document.querySelector('#script-list-sort .list-option:nth-child(1)'));
  2039. dailyOption && dailyOption.insertAdjacentHTML('beforeend', `<span> (${dailyInstallsSum.toLocaleString()}${plusSign})</span>`);
  2040.  
  2041. const totalOption = convertLi(document.querySelector('#script-list-sort .list-option:nth-child(2)'));
  2042. totalOption && totalOption.insertAdjacentHTML('beforeend', `<span> (${totalInstallsSum.toLocaleString()}${plusSign})</span>`);
  2043. }
  2044.  
  2045. // milestone notification
  2046. if (gmc.get('milestoneNotification')) {
  2047. milestoneNotificationFn({ userLink, userID });
  2048. }
  2049.  
  2050. if (isScriptFirstUse) GM.setValue('firstUse', false).then(() => {
  2051. gmc.open();
  2052. });
  2053.  
  2054. if (fixLibraryScriptCodeLink) {
  2055.  
  2056.  
  2057. let xpath = "//code[contains(text(), '.js?version=') or contains(text(), '// @require https://update.greasyfork.org/scripts/')]";
  2058. let snapshot = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  2059.  
  2060. for (let i = 0; i < snapshot.snapshotLength; i++) {
  2061. let element = snapshot.snapshotItem(i);
  2062. if (element.firstElementChild) continue;
  2063. element.textContent = element.textContent.replace(/\bhttps:\/\/(greasyfork|sleazyfork)\.org\/scripts\/\d+\-[^\/]+\/code\/[^\.]+\.js\?version=\d+\b/, (_) => {
  2064. return fixLibraryCodeURL(_);
  2065. });
  2066. element.parentNode.insertBefore(document.createTextNode('\u200B'), element);
  2067. element.style.display = 'inline-flex';
  2068. setClickToSelect(element);
  2069. }
  2070.  
  2071.  
  2072. }
  2073.  
  2074.  
  2075.  
  2076.  
  2077. if (addAdditionInfoLengthHint && location.pathname.includes('/scripts/') && location.pathname.includes('/versions')) {
  2078.  
  2079. function contentLength(text) {
  2080. return text.replace(/\n/g, ' ').length;
  2081. }
  2082. function contentLengthMax() {
  2083. return 50000;
  2084. }
  2085. let _spanContent = null;
  2086. function updateText(ainfo, span) {
  2087. const value = ainfo.value;
  2088. if (typeof value !== 'string') return;
  2089.  
  2090. if (_spanContent !== value) {
  2091. _spanContent = value;
  2092. span.textContent = `Text Length: ${contentLength(value)} / ${contentLengthMax()}`;
  2093.  
  2094.  
  2095. }
  2096. }
  2097. function onChange(evt) {
  2098. let ainfo = (evt || 0).target;
  2099. if (!ainfo) return;
  2100. let span = ainfo.parentNode.querySelector('.script-version-ainfo-span');
  2101. if (!span) return;
  2102.  
  2103. updateText(ainfo, span);
  2104.  
  2105. }
  2106. function kbEvent(evt) {
  2107. Promise.resolve().then(() => {
  2108. onChange(evt);
  2109.  
  2110. })
  2111. }
  2112. for (const ainfo of document.querySelectorAll('textarea[id^="script-version-additional-info"]')) {
  2113. let span = document.createElement('span');
  2114. span.classList.add('script-version-ainfo-span');
  2115. ainfo.addEventListener('change', onChange, false);
  2116. ainfo.addEventListener('keydown', kbEvent, false);
  2117. ainfo.addEventListener('keypress', kbEvent, false);
  2118. ainfo.addEventListener('keyup', kbEvent, false);
  2119. updateText(ainfo, span);
  2120. ainfo.parentNode.insertBefore(span, ainfo.nextSibling);
  2121.  
  2122.  
  2123. }
  2124.  
  2125.  
  2126. }
  2127.  
  2128. } catch (e) {
  2129. console.log(e);
  2130. }
  2131.  
  2132.  
  2133.  
  2134. }
  2135.  
  2136.  
  2137.  
  2138.  
  2139. Promise.resolve().then(() => {
  2140. if (document.readyState !== 'loading') {
  2141. onReady();
  2142. } else {
  2143. window.addEventListener("DOMContentLoaded", onReady, false);
  2144. }
  2145. });
  2146.  
  2147. })();