Reddit - Auto-Translation Bypass / Redirect back to original post

Bypasses translated pages by removing "tl" parameter after 5 seconds and redirecting towards it (cancel option available)

  1. // ==UserScript==
  2. // @name Reddit - Auto-Translation Bypass / Redirect back to original post
  3. // @namespace https://nemeth.it/
  4. // @version 0.2
  5. // @description Bypasses translated pages by removing "tl" parameter after 5 seconds and redirecting towards it (cancel option available)
  6. // @license MIT
  7. // @author nemeth.it
  8. // @match *://*.reddit.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to check if the "tl" parameter exists in the URL
  16. function hasParameter(name) {
  17. return new URL(window.location.href).searchParams.has(name);
  18. }
  19.  
  20. // Removes the "tl" parameter from the URL and reloads the page
  21. function reloadWithoutParameter() {
  22. const url = new URL(window.location.href);
  23. url.searchParams.delete("tl");
  24. window.location.href = url.toString();
  25. }
  26.  
  27. // Displays the notice with a cancel button
  28. function showNotice() {
  29. // Create the notice element
  30. const notice = document.createElement("div");
  31. notice.style.position = "fixed";
  32. notice.style.bottom = "20px";
  33. notice.style.right = "20px";
  34. notice.style.padding = "15px";
  35. notice.style.backgroundColor = "#000000";
  36. notice.style.color = "#ffffff";
  37. notice.style.border = "1px solid #333333";
  38. notice.style.borderRadius = "5px";
  39. notice.style.boxShadow = "0px 4px 8px rgba(0, 0, 0, 0.5)";
  40. notice.style.zIndex = "10000";
  41. notice.style.fontFamily = "Arial, sans-serif";
  42. notice.innerHTML = "This page will reload in 5 seconds without the 'tl' parameter.";
  43.  
  44. // Countdown timer
  45. let countdown = 5;
  46. const countdownText = document.createElement("span");
  47. countdownText.style.marginRight = "10px";
  48. countdownText.innerText = ` (${countdown}s)`;
  49. notice.appendChild(countdownText);
  50.  
  51. // Cancel button
  52. const cancelButton = document.createElement("button");
  53. cancelButton.innerText = "Cancel";
  54. cancelButton.style.padding = "5px 10px";
  55. cancelButton.style.marginLeft = "10px";
  56. cancelButton.style.border = "none";
  57. cancelButton.style.backgroundColor = "#d32f2f";
  58. cancelButton.style.color = "#ffffff";
  59. cancelButton.style.borderRadius = "3px";
  60. cancelButton.style.cursor = "pointer";
  61. cancelButton.style.fontSize = "14px";
  62. cancelButton.style.textAlign = "center";
  63. cancelButton.style.display = "inline-flex";
  64. cancelButton.style.alignItems = "center";
  65. cancelButton.onclick = function() {
  66. clearInterval(timer);
  67. document.body.removeChild(notice);
  68. };
  69. notice.appendChild(cancelButton);
  70.  
  71. document.body.appendChild(notice);
  72.  
  73. // Countdown and automatic reload
  74. const timer = setInterval(function() {
  75. countdown -= 1;
  76. countdownText.innerText = ` (${countdown}s)`;
  77.  
  78. if (countdown <= 0) {
  79. clearInterval(timer);
  80. reloadWithoutParameter();
  81. }
  82. }, 1000);
  83.  
  84. // Watch for AJAX removal of the "tl" parameter
  85. const ajaxCheckInterval = setInterval(() => {
  86. if (!hasParameter("tl")) {
  87. clearInterval(ajaxCheckInterval);
  88. setTimeout(() => {
  89. if (document.body.contains(notice)) {
  90. document.body.removeChild(notice);
  91. }
  92. }, 1000); // Remove notice after a 1-second delay
  93. }
  94. }, 500); // Check every 0.5 seconds
  95. }
  96.  
  97. // Script logic: Check if "tl" parameter exists and show the notice
  98. if (hasParameter("tl")) {
  99. showNotice();
  100. }
  101. })();