Created
March 15, 2020 17:21
-
-
Save nikhilkumarsingh/11de9d7cb1221545a61c9a0294e7c7b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Codechef IO Copy | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author nikhilksingh97 | |
// @match https://www.codechef.com/problems/* | |
// @grant none | |
// ==/UserScript== | |
let styleSheet = ` | |
.copyBtn { | |
background-color: green; | |
padding: 5px; | |
font-size: 12px; | |
} | |
`; | |
let s = document.createElement('style'); | |
s.type = "text/css"; | |
s.innerHTML = styleSheet; | |
(document.head || document.documentElement).appendChild(s); | |
window.addEventListener('load', function() { | |
'use strict'; | |
function copy(ele) { | |
let temp = document.createElement('textarea'); | |
document.body.appendChild(temp); | |
temp.value = ele.textContent; | |
temp.select(); | |
document.execCommand('copy'); | |
temp.remove(); | |
} | |
function addCopyBtn(ele) { | |
let btn = document.createElement("button"); | |
btn.innerHTML = "Copy"; | |
btn.className = "copyBtn"; | |
btn.onclick = () => { | |
copy(ele.lastChild); | |
} | |
ele.insertBefore(document.createElement('br'), ele.childNodes[0]); | |
ele.insertBefore(btn, ele.childNodes[0]); | |
} | |
let preTags = document.getElementsByTagName("pre"); | |
console.log(preTags); | |
for (let preTag of preTags) { | |
addCopyBtn(preTag); | |
} | |
}); |
is it work for make spam?
lol
Wheare i can do userscrip?
Thank you. My great teacher.❤️❤️❤️❤️❤️ In my case, it doesn't work in Chrome browser. But it works in Edge browser. Maybe That my Chrome browser has installed too many plugins leads to this failure.
document.execCommand() method has been discarded. Maybe you should change the 33th line code to the code below
navigator.clipboard.writeText(temp.value);
you can find solutions in this discussion、mdn document about clipboard and mdn document about execCommand.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks