Skip to content

Instantly share code, notes, and snippets.

@nzec
Last active July 25, 2026 20:45
Show Gist options
  • Select an option

  • Save nzec/2aefd0f4763b68e7cddc1e22b070774c to your computer and use it in GitHub Desktop.

Select an option

Save nzec/2aefd0f4763b68e7cddc1e22b070774c to your computer and use it in GitHub Desktop.
enable-copy-paste-nptel.user.js
// ==UserScript==
// @name Enable copy/patse on NPTEL
// @namespace https://gist.github.com/nzec
// @version 1.4
// @description Enable copy/paste on NPTEL
// @author nzec
// @license MIT
// @match *://*.nptel.ac.in/*
// @match *://nptel.ac.in/*
// @match *://*.swayam.gov.in/*
// @match *://swayam.gov.in/*
// @grant none
// @run-at document-start
// @downloadURL https://gist.githubusercontent.com/nzec/2aefd0f4763b68e7cddc1e22b070774c/raw/enable-copy-paste-nptel.user.js
// @updateURL https://gist.githubusercontent.com/nzec/2aefd0f4763b68e7cddc1e22b070774c/raw/enable-copy-paste-nptel.user.js
// ==/UserScript==
(function () {
'use strict';
const enable = () => {
// Force selectable text via injected CSS
const style = document.createElement('style');
style.textContent = `
* {
user-select: auto !important;
-webkit-user-select: auto !important;
-moz-user-select: auto !important;
-ms-user-select: auto !important;
}
`;
(document.head || document.documentElement).appendChild(style);
};
// Kill the common blocking event handlers
const events = ['copy', 'cut', 'paste', 'contextmenu', 'selectstart', 'mousedown', 'mouseup', 'dragstart', 'keydown'];
events.forEach(evt => {
document.addEventListener(evt, e => e.stopPropagation(), true);
});
// Clear inline on* handlers that block selection/copy
const clearInline = () => {
['onselectstart', 'oncontextmenu', 'oncopy', 'oncut', 'onpaste', 'ondragstart', 'onmousedown'].forEach(h => {
try {
document.body && (document.body[h] = null);
document[h] = null;
} catch (e) {}
});
};
if (document.body) { enable(); clearInline(); }
document.addEventListener('DOMContentLoaded', () => { enable(); clearInline(); });
window.addEventListener('load', () => { enable(); clearInline(); });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment