|
3 | 3 | // @namespace HKR |
4 | 4 | // @match https://pixlr.com/*/* |
5 | 5 | // @grant none |
6 | | -// @version 1.0 |
| 6 | +// @version 1.1 |
7 | 7 | // @author HKR |
8 | 8 | // @description Bypasses the daily save limit |
9 | 9 | // @run-at document-start |
|
13 | 13 | const replacementRegex = /\(\)\s*>=\s*3/g; |
14 | 14 | const bypassStr = `()=='D'`; |
15 | 15 |
|
16 | | - function patchNode(node) { |
17 | | - node?.remove(); |
| 16 | + if (typeof InstallTrigger !== 'undefined') { |
| 17 | + // Firefox method |
| 18 | + function patchScript(event) { |
| 19 | + const script = event.target; |
| 20 | + const src = script?.src; |
18 | 21 |
|
19 | | - fetch(node.src) |
20 | | - .then(res => res.text()) |
21 | | - .then(text => { |
22 | | - text = text.replace(replacementRegex, bypassStr); |
| 22 | + if (src && src.includes('/dist/')) { |
| 23 | + event.preventDefault(); |
23 | 24 |
|
24 | | - if(!text.includes(bypassStr)) { |
25 | | - alert(`Daily limit bypass failed, the userscript may be outdated!`); |
26 | | - } |
| 25 | + fetch(src) |
| 26 | + .then(res => res.text()) |
| 27 | + .then(text => { |
| 28 | + text = text.replace(replacementRegex, bypassStr); |
27 | 29 |
|
28 | | - const newNode = document.createElement('script'); |
29 | | - newNode.innerHTML = text; |
| 30 | + if (!text.includes(bypassStr)) { |
| 31 | + alert(`Daily limit bypass failed, the userscript may be outdated!`); |
| 32 | + } |
30 | 33 |
|
31 | | - document.body.appendChild(newNode); |
| 34 | + const modifiedScript = document.createElement('script'); |
| 35 | + modifiedScript.innerHTML = text; |
| 36 | + |
| 37 | + script.parentNode.replaceChild(modifiedScript, script); |
| 38 | + }); |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + document.addEventListener('beforescriptexecute', patchScript, true); |
| 43 | + } else { |
| 44 | + // Chrome method |
| 45 | + function patchNode(node) { |
| 46 | + node?.remove(); |
| 47 | + |
| 48 | + fetch(node.src) |
| 49 | + .then(res => res.text()) |
| 50 | + .then(text => { |
| 51 | + text = text.replace(replacementRegex, bypassStr); |
| 52 | + |
| 53 | + if (!text.includes(bypassStr)) { |
| 54 | + alert(`Daily limit bypass failed, the userscript may be outdated!`); |
| 55 | + } |
| 56 | + |
| 57 | + const newNode = document.createElement('script'); |
| 58 | + newNode.innerHTML = text; |
| 59 | + |
| 60 | + document.body.appendChild(newNode); |
| 61 | + }); |
| 62 | + } |
| 63 | + |
| 64 | + new MutationObserver(mutationsList => { |
| 65 | + mutationsList.forEach(mutationRecord => { |
| 66 | + [...mutationRecord.addedNodes] |
| 67 | + .filter(node => node.tagName === 'SCRIPT' && node.src?.includes('/dist/')) |
| 68 | + .forEach(node => patchNode(node)); |
32 | 69 | }); |
| 70 | + }).observe(document, { childList: true, subtree: true }); |
33 | 71 | } |
34 | | - |
35 | | - new MutationObserver(mutationsList => { |
36 | | - mutationsList.forEach(mutationRecord => { |
37 | | - [...mutationRecord.addedNodes] |
38 | | - .filter(node => node.tagName === 'SCRIPT' && node.src?.includes('/dist/')) |
39 | | - .forEach(node => patchNode(node)); |
40 | | - }); |
41 | | - }).observe(document, { childList: true, subtree: true }); |
42 | 72 | })(); |
0 commit comments