Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Withhive Board Enable New Tab Links
- // @namespace http://tampermonkey.net/
- // @author Vic2780
- // @description allow new tabs for links on these godforsaken boards
- // @match https://community.withhive.com/*
- // ==/UserScript==
- (function() {
- 'use strict';
- function convertPostIDs() {
- document.querySelectorAll('li[onclick^="detail"]').forEach(li => {
- const match = li.getAttribute('onclick')?.match(/detail\('(\d+)'\s*,\s*'(\d+)'\)/);
- if (!match) return;
- const boardId = match[1];
- const postId = match[2];
- const realUrl = `https://community.withhive.com/dvc/board/${boardId}/${postId}`;
- // bin the evil onclick
- li.removeAttribute('onclick');
- // replace the weird fake href
- const a = li.querySelector('a[href="javascript:;"]');
- if (a) {
- a.href = realUrl;
- a.target = '_blank';
- a.rel = 'noopener noreferrer';
- }
- });
- }
- // for new posts that load without actually reloading the page
- // the site loves to pretend that it is an app
- const observer = new MutationObserver(() => convertPostIDs());
- observer.observe(document.body, { childList: true, subtree: true });
- window.addEventListener('DOMContentLoaded', convertPostsIds);
- })();
Advertisement
Add Comment
Please, Sign In to add comment