Guest User

Untitled

a guest
Feb 10th, 2021
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name     AliExpress Shipping Countries
  3. // @version  1
  4. // @include  https://www.aliexpress.com/wholesale*
  5. // @include  https://www.aliexpress.com/w/wholesale*
  6. // @grant    GM.xmlHttpRequest
  7. // @run-at   document-start
  8. // ==/UserScript==
  9. //
  10. // Licensed as public domain under the terms of Unlicense <http://unlicense.org/>
  11.  
  12.             const Event = class {
  13.                 constructor(script, target) {
  14.                     this.script = script;
  15.                     this.target = target;
  16.  
  17.                     this._cancel = false;
  18.                     this._replace = null;
  19.                     this._stop = false;
  20.                 }
  21.  
  22.                 preventDefault() {
  23.                     this._cancel = true;
  24.                 }
  25.                 stopPropagation() {
  26.                     this._stop = true;
  27.                 }
  28.                 replacePayload(payload) {
  29.                     this._replace = payload;
  30.                 }
  31.             };
  32.  
  33.             let callbacks = [];
  34.             window.addBeforeScriptExecuteListener = (f) => {
  35.                 if (typeof f !== "function") {
  36.                     throw new Error("Event handler must be a function.");
  37.                 }
  38.                 callbacks.push(f);
  39.             };
  40.             window.removeBeforeScriptExecuteListener = (f) => {
  41.                 let i = callbacks.length;
  42.                 while (i--) {
  43.                     if (callbacks[i] === f) {
  44.                         callbacks.splice(i, 1);
  45.                     }
  46.                 }
  47.             };
  48.  
  49.             const dispatch = (script, target) => {
  50.                 if (script.tagName !== "SCRIPT") {
  51.                     return;
  52.                 }
  53.  
  54.                 const e = new Event(script, target);
  55.  
  56.                 if (typeof window.onbeforescriptexecute === "function") {
  57.                     try {
  58.                         window.onbeforescriptexecute(e);
  59.                     } catch (err) {
  60.                         console.error(err);
  61.                     }
  62.                 }
  63.  
  64.                 for (const func of callbacks) {
  65.                     if (e._stop) {
  66.                         break;
  67.                     }
  68.                     try {
  69.                         func(e);
  70.                     } catch (err) {
  71.                         console.error(err);
  72.                     }
  73.                 }
  74.  
  75.                 if (e._cancel) {
  76.                     script.textContent = "";
  77.                     script.remove();
  78.                 } else if (typeof e._replace === "string") {
  79.                     script.textContent = e._replace;
  80.                 }
  81.             };
  82.             const observer = new MutationObserver((mutations) => {
  83.                 for (const m of mutations) {
  84.                     for (const n of m.addedNodes) {
  85.                         dispatch(n, m.target);
  86.                     }
  87.                 }
  88.             });
  89.             observer.observe(document, {
  90.                 childList: true,
  91.                 subtree: true,
  92.             });
  93.  
  94.             window.onbeforescriptexecute = (e) => {
  95.                 // You should check if textContent exists as this property is
  96.                 // buggy sometimes
  97.                 if (!e.script.textContent) {
  98.                     return;
  99.                 }
  100.  
  101.                 // Prevent execution of a script
  102.                 if (e.script.textContent.includes("alert")) {
  103.                     e.preventDefault();
  104.                 }
  105.  
  106.                 // Change the code that runs
  107.                 if (e.script.textContent.includes("refineShipFromCountries")) {
  108.                     // Original payload is e.script.textContent, you can
  109.                     // manipulate it however you want, just pass the final
  110.                     // payload to e.replacePayload when you are done
  111.                     //e.replacePayload("console.log(2);");
  112.                     //e.preventDefault();
  113.                     e.replacePayload(e.script.textContent.replace('"refineShipFromCountries":[', '"refineShipFromCountries":[{countryCode: "CZ", countryName: "Czechia", selected: false},{countryCode: "PL", countryName: "Poland", selected: false},{countryCode: "DE", countryName: "Germany", selected: false},{countryCode: "FR", countryName: "France", selected: false},{countryCode: "ES", countryName: "Spain", selected: false},{countryCode: "IT", countryName: "Italy", selected: false},'));
  114.                     // Later event handlers can override your payload, you
  115.                     // can call e.stopPropagation to make sure the current
  116.                     // payload is applied
  117.                 }
  118.             };
  119.  
Advertisement
Add Comment
Please, Sign In to add comment