Last active
August 20, 2018 18:15
-
-
Save sutlxwhx/bf799bd97d519f973653785d018f5460 to your computer and use it in GitHub Desktop.
Copy to the clipborad list of all h1/h2/h3 elements on the page
This file contains 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
# Declare tag name that you want to extract | |
var elements = document.getElementsByTagName("h2"); | |
# Create a temporary element where all the data will be stored | |
var buffer = document.createElement("buffer"); | |
document.body.appendChild(buffer); | |
# Declare the string var where all the data from the page will be stored | |
var names = ''; | |
# Create a foor loop and append all new elements to the string | |
for(var i=0; i<elements.length; i++) { | |
names += elements[i].innerText + '\n';; | |
} | |
# Merge temporary element data with acquired data from the current page | |
buffer.innerText = names.toString(); | |
# Use native Javascript command to copy the gathered data | |
# https://developers.google.com/web/updates/2015/04/cut-and-copy-commands | |
var range = document.createRange(); | |
range.selectNode(buffer); | |
window.getSelection().addRange(range); | |
# Perform the copy to clipboard process | |
document.execCommand("copy"); | |
# Delete the temporary element with all tag data | |
document.body.removeChild(buffer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment