Guest User

Untitled

a guest
May 31st, 2025
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Withhive Board Enable New Tab Links
  3. // @namespace http://tampermonkey.net/
  4. // @author Vic2780
  5. // @description allow new tabs for links on these godforsaken boards
  6. // @match https://community.withhive.com/*
  7. // ==/UserScript==
  8.  
  9. (function() {
  10. 'use strict';
  11.  
  12. function convertPostIDs() {
  13. document.querySelectorAll('li[onclick^="detail"]').forEach(li => {
  14. const match = li.getAttribute('onclick')?.match(/detail\('(\d+)'\s*,\s*'(\d+)'\)/);
  15. if (!match) return;
  16.  
  17. const boardId = match[1];
  18. const postId = match[2];
  19. const realUrl = `https://community.withhive.com/dvc/board/${boardId}/${postId}`;
  20.  
  21. // bin the evil onclick
  22. li.removeAttribute('onclick');
  23.  
  24. // replace the weird fake href
  25. const a = li.querySelector('a[href="javascript:;"]');
  26. if (a) {
  27. a.href = realUrl;
  28. a.target = '_blank';
  29. a.rel = 'noopener noreferrer';
  30. }
  31. });
  32. }
  33.  
  34. // for new posts that load without actually reloading the page
  35. // the site loves to pretend that it is an app
  36. const observer = new MutationObserver(() => convertPostIDs());
  37. observer.observe(document.body, { childList: true, subtree: true });
  38.  
  39. window.addEventListener('DOMContentLoaded', convertPostsIds);
  40. })();
Advertisement
Add Comment
Please, Sign In to add comment