Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2025
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Tokopedia Hardcore Pre-Load URL Cleaner
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  5. // @description Force early redirect to clean Tokopedia search URLs before any frontend code runs. Fixes SPA hijacking issues. Uses inline injection to bypass Tampermonkey delay.
  6. // @author You
  7. // @match https://www.tokopedia.com/*
  8. // @run-at document-start
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. const junkParams = [
  13. 'minus_ids',
  14. 'search_id',
  15. 'has_more',
  16. 'next_offset_organic',
  17. 'next_offset_organic_ad',
  18. 'navsource',
  19. 'srp_component_id',
  20. 'srp_page_id',
  21. 'srp_page_title',
  22. 'st',
  23. '_sort',
  24. '_useSearchResultTracking'
  25. ];
  26.  
  27. const scriptContent = `
  28. (function() {
  29. const url = new URL(window.location.href);
  30. const params = url.searchParams;
  31. let changed = false;
  32.  
  33. const junk = ${JSON.stringify(junkParams)};
  34. junk.forEach(p => {
  35. if (params.has(p)) {
  36. params.delete(p);
  37. changed = true;
  38. }
  39. });
  40.  
  41. if (changed) {
  42. const cleaned = \`\${url.origin}\${url.pathname}?\${params.toString()}\`;
  43. window.location.replace(cleaned);
  44. }
  45. })();
  46. `;
  47.  
  48. const script = document.createElement('script');
  49. script.textContent = scriptContent;
  50. document.documentElement.prepend(script);
  51. })();
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement