Advertisement
Steve5451

That post isn't new! 1.4.3

May 4th, 2016
21,736
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         That post isn't new!
  3. // @version      1.4.3
  4. // @description  badspot pls fix
  5. // @author       Steve5451
  6. // @namespace    http://thepotato.net/
  7. // @match        https://forum.blockland.us/index.php*
  8. // @updateURL    http://pastebin.com/raw/5v9JW4hi
  9. // @downloadURL  http://pastebin.com/raw/5v9JW4hi
  10. // @grant        none
  11. // @noframes
  12. // ==/UserScript==
  13. /* Known bugs:
  14. Much like any hacky script it's not 100% successful.
  15.  Please PM me if you discover any bugs at https://forum.blockland.us/index.php?action=profile;u=132993   */
  16.  
  17. const maxLength = 64; // How many posts to store as read. 64 is probably enough but feel free to change it. (about half a kilobyte)
  18.  
  19. // ================================================= You probably shouldn't edit below this line ======================================================= //
  20.  
  21. const username = document.getElementsByClassName("logoLink")[0].parentNode.parentNode.parentNode.children[1].children[0].innerHTML || ""; // Get our username from "Hey, NAME, you have..."
  22.  
  23. if(localStorage.seenMessages === undefined)
  24.     localStorage.seenMessages = "[]";
  25.  
  26. var seenMessages = JSON.parse(localStorage.seenMessages) || [];
  27.  
  28. if(window.location.href.startsWith("https://forum.blockland.us/index.php?topic=")) { // We're in a thread
  29.     if(window.location.href.includes("&postTime=")) { // This URL has the postTime specified by my script.
  30.         var postTime = window.location.href.split("&postTime=")[1].split("#")[0]; // Get the post time
  31.  
  32.         seenMessages.unshift(postTime); // Add to list
  33.         seenMessages = seenMessages.slice(0, maxLength); // Cut list down to the size specified by maxLength so it doesn't become too big
  34.  
  35.         localStorage.seenMessages = JSON.stringify(seenMessages) || []; // Store list
  36.  
  37.         window.history.replaceState(null, null, window.location.href.substr(0, window.location.href.indexOf("&postTime=")) || null); // Remove &postTime from our URL, for copying purposes.
  38.     }
  39. } else if(window.location.href.startsWith("https://forum.blockland.us/index.php?board=")) { // Board
  40.     var images = document.querySelectorAll('img[src*="/new.gif"'); // Get all (new) images
  41.  
  42.     for(i = 0; i < images.length; i++) {
  43.         if(images[i].parentNode.parentNode.parentNode.children[5].children[0].children.length > 2) { // Post from today or yesterday
  44.             var postTime = images[i].parentNode.parentNode.parentNode.children[5].children[0].innerHTML.split(" at ")[1].split("<br>by ")[0].replace(/\D/g,''); // Get the time of the post
  45.         } else { // Post from an older date
  46.             var postTime = images[i].parentNode.parentNode.parentNode.children[5].children[0].innerHTML.split("<br>by ")[0].replace(/\D/g,'');
  47.         }
  48.  
  49.         if(images[i].parentNode.parentNode.parentNode.children[5].children[0].lastChild.innerHTML === username) { // Is this my post?
  50.             images[i].style.display = "none"; // Hide the (new) button
  51.         } else if(seenMessages.includes(postTime)) { // It wasn't. Perhaps it's on our list?
  52.             images[i].style.display = "none";
  53.         } else { // It has not been seen.
  54.             images[i].parentNode.parentNode.children[0].href += "&postTime=" + postTime; // Modify the url so that it passes its last post date when it's clicked
  55.             images[i].parentNode.href = images[i].parentNode.href.replace("#new","&postTime=" + postTime + "#new");
  56.         }
  57.     }
  58. } else if(window.location.href.startsWith("https://forum.blockland.us/index.php?action=unreadreplies")) { // Unread repies page
  59.     var images = document.querySelectorAll('img[src*="/new.gif"'); // Get all (new) images
  60.  
  61.     for(i = 0; i < images.length; i++) {
  62.         if(images[i].parentNode.parentNode.parentNode.children[6].children[0].children.length > 2) // Post from today or yesterday
  63.             var postTime = images[i].parentNode.parentNode.parentNode.children[6].children[0].innerHTML.split(" at ")[1].split("<br>by ")[0].replace(/\D/g,'');
  64.         else // Post from an older date
  65.             var postTime = images[i].parentNode.parentNode.parentNode.children[6].children[0].innerHTML.split(",")[2].split("<br>by ")[0].replace(/\D/g,'');
  66.  
  67.         if(images[i].parentNode.parentNode.parentNode.children[6].children[0].lastChild.innerHTML === username) // Is this my post?
  68.             images[i].parentNode.parentNode.parentNode.style.display = "none"; // Hide the row
  69.         else if(seenMessages.includes(postTime)) // It wasn't. Perhaps it's on our list?
  70.             images[i].parentNode.parentNode.parentNode.style.display = "none";
  71.     }
  72. } else { // We're somewhere else. As far as I know these images only exist on the index and Help. Let's run it.
  73.     var images = document.querySelectorAll('img[src*="/on.gif"'); // This time we're getting all of the lamp images
  74.  
  75.     for(i = 0; i < images.length; i++) {
  76.         var postUsername = images[i].parentNode.parentNode.children[4].children[0],
  77.             postDate;
  78.  
  79.         if(postUsername.children.length > 4) { // Post is within two days old.
  80.             postDate = postUsername.innerHTML.split("</b> at ")[1].split(" ")[0].replace(/\D/g,'');
  81.             postUsername = postUsername.children[4].innerHTML;  // Get the username of the last post
  82.         } else { // Post is over two days old.
  83.             postDate = postUsername.innerHTML.split(", ")[2].split("<br>")[0].replace(/\D/g,'');
  84.             postUsername = postUsername.children[3].innerHTML;
  85.         }
  86.  
  87.         if(postUsername === username) // Do we have the last post on that board?
  88.             images[i].src = "https://forum.blockland.us/Themes/Blockland/images/off.gif"; // Yes, so let's dim the lamp.
  89.         else if(seenMessages.includes(postDate))
  90.             images[i].src = "https://forum.blockland.us/Themes/Blockland/images/off.gif";
  91.     }
  92. }
  93.  
  94. /* Changelog:
  95.  
  96. 1.0   - Initial release
  97. 1.1   - Updated Topics page support
  98. 1.2   - Updated Topics page now removes the thread instead of hiding the (new) button. Added support for the Index lamps.
  99. 1.3   - Remembers viewed posts to hide all read (new) posts + bugfix.
  100. 1.4   - Way more reliable now.
  101. 1.4.1 - Updated Topics bug fix and a few lines of debug code removed.
  102. 1.4.2 - &postTime removed from URL for copying purposes, increased stored posts, and minor bugfix.
  103. 1.4.3 - Fixed bug from last patch.
  104.  
  105. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement