Advertisement
jcunews

tiktok.com-Not-Found-landing-page-restore-initial-URL.user.js

Mar 15th, 2023 (edited)
1,527
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        tiktok.com Not-Found landing page restore initial URL
  3. // @namespace   https://greasyfork.org/en/users/85671-jcunews
  4. // @version     1.0.1
  5. // @license     AGPL v3
  6. // @author      jcunews
  7. // @description Context: https://www.reddit.com/r/userscripts/comments/11m0a61/can_someone_make_a_simple_script_that_doesnt_let/
  8. // @match       *://*/*
  9. // @include     *:*
  10. // @grant       GM_getValue
  11. // @grant       GM_setValue
  12. // @run-at      document-start
  13. // ==/UserScript==
  14.  
  15. /*
  16. Notes:
  17. - Only work when clicking a true HTML link with URL. i.e. will not work for fake links, buttons, JavaScript driven links,
  18.   web browser bookmark, or if an URL is entered into browser addressbar.
  19. - May sometimes not work if the link is on a page presented within an IFRAME. This is due to a bug in the GM provider browser
  20.   extension (i.e. TamperMonkey, ViolentMonkey, etc.) where scripts may or may not run on page presented within an IFRAME.
  21. */
  22.  
  23. (url => {
  24.   if (location.hostname === "www.tiktok.com") {
  25.     if (/:\/\/www\.tiktok\.com\/notfound/.test(location.href) && (url = GM_getValue("url", ""))) addEventListener("load", () => history.pushState({}, "", url));
  26.     addEventListener("load", () => {
  27.       setTimeout(() => GM_setValue("url", ""), 2000)
  28.     })
  29.   }
  30.   addEventListener("mousedown", e => {
  31.     if ((e = e.target).closest && (e = e.closest("a")) && /^(www\.)tiktok\.com$/.test(e.hostname)) GM_setValue("url", e.href)
  32.   }, true)
  33. })()
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement