Files
vm-userscripts/KnowledgeHub - Remove no-copy class.user.js
T
2026-06-15 14:20:38 -04:00

58 lines
2.1 KiB
JavaScript

// ==UserScript==
// @name KnowledgeHub - Remove no-copy class
// @namespace https://github.com/yourname/
// @version 1.0
// @description Removes the "no-copy" class from body to allow text selection and copying
// @author You
// @match https://www.knowledgehub.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
document.addEventListener('contextmenu', e => e.stopPropagation(), true);
// Prevent text selection blocking
document.addEventListener('selectstart', e => e.stopPropagation(), true);
// Prevent dragstart blocking
document.addEventListener('dragstart', e => e.stopPropagation(), true);
// Stop blocking copy and cut events
document.addEventListener('copy', e => e.stopPropagation(), true);
document.addEventListener('cut', e => e.stopPropagation(), true);
// Prevent scripts from blocking pasting
document.addEventListener('paste', e => e.stopPropagation(), true);
(function() {
'use strict';
function removeNoCopyClass() {
if (document.body) {
document.body.classList.remove('no-copy');
// Optional: completely clear the class attribute if it only had "no-copy"
// document.body.className = document.body.className.replace(/\bno-copy\b/g, '').trim();
}
}
// Run as early as possible
if (document.body) {
removeNoCopyClass();
} else {
// Fallback: wait for body to be available
const observer = new MutationObserver(() => {
if (document.body) {
removeNoCopyClass();
observer.disconnect();
}
});
observer.observe(document.documentElement, { childList: true });
}
// Also run again after page is fully loaded (in case the site re-adds the class)
window.addEventListener('load', removeNoCopyClass);
// Optional: re-run every time the class changes (very aggressive)
// const classObserver = new MutationObserver(removeNoCopyClass);
// if (document.body) classObserver.observe(document.body, { attributes: true, attributeFilter: ['class'] });
})();