Created
March 15, 2020 20:26
-
-
Save nikhilkumarsingh/6c3756baad82d8ad70e3fda3a493e651 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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Writing TamperMonkey UserScripts\n", | |
"\n", | |
"\n", | |
"- [Install TamperMonkey](https://www.tampermonkey.net/)\n", | |
"- [JavaScript HTML DOM](https://www.w3schools.com/js/js_htmldom.asp)\n", | |
"- [Finding HTML Elements](https://www.w3schools.com/js/js_htmldom_elements.asp)\n", | |
"- [HTML DOM createElement() Method](https://www.w3schools.com/jsref/met_document_createelement.asp)\n", | |
"\n", | |
"------" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Copy Element Text to ClipBoard\n", | |
"\n", | |
"```js\n", | |
"function copy(ele) {\n", | |
" let temp = document.createElement('textarea');\n", | |
" document.body.appendChild(temp);\n", | |
" temp.value = ele.textContent;\n", | |
" temp.select();\n", | |
" document.execCommand('copy');\n", | |
" temp.remove();\n", | |
"}\n", | |
"```" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Wait for Window to Load Before Executing JS Function\n", | |
"\n", | |
"\n", | |
"```js\n", | |
"window.addEventListener('load', function() {\n", | |
" // your code here\n", | |
"});\n", | |
"```" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.9" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
TamperMonkey has a built-in option for loading JS before or after document-load!
Great and very helpful video. Thanks!
The @run-at document-idle
was not working for me for some reason? The addEventListener
method however works as expected.
Thank you! That was very helpful.
@optionsx Thanks. More info:
* by default tampermonkey script runs after page loads * the option is `@run-at document-idle` * refer [this](https://www.tampermonkey.net/documentation.php#_run_at) for other options
yes but sometimes you may want to load some of the code after the page loads, and the rest while before the page completely is loaded. if you know what i mean
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok