Last active
November 13, 2024 22:36
-
-
Save jhauga/80fa99670b2d27c373e11e485ba451bd to your computer and use it in GitHub Desktop.
Bookmarklet - use this bookmarklet for Add a button to extract an answers id, adding it to address bar as anchor link, and copy full url to the clipboard. dds button to bottom of voting area for all answers. Use to easily bookmark and reference a StackOverflow answer. Ensure to copy/paste the top condensed line of the bookmarklet. Info at "https…
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
/// *********************************************************** /// | |
// ****************** BROWSER BOOKMARKLET GIST ***************** // | |
// ************************************************************* // | |
// // | |
// LICENSE ///////////////////////////////////////////////////// | |
// ******* // | |
// The code in this gist is public domain. // | |
// Licensed as Public Domain CC0 // | |
////////////////////////////////////////////////////////////////// | |
// | |
// COPY / PAST BELOW LINE TO USE | |
javascript: (function () { var answers = document.getElementsByClassName("answer"); var answersLen = answers.length; var votingContainer; for (i = 0; i < answersLen; i++) { votingContainer = answers[i].getElementsByClassName("js-voting-container")[0]; let anchorButton = document.createElement("a"); anchorButton.innerHTML = "| # |"; anchorButton.setAttribute("href", "#" + answers[i].id); anchorButton.style.marginTop = "10px"; anchorButton.style.marginLeft = "12px"; anchorButton.style.color = "gray"; votingContainer.insertAdjacentElement("beforeend", anchorButton); anchorButton.addEventListener("click", function() { setTimeout(function() { navigator.clipboard.writeText(anchorButton.href); }, 100); }); }})(); | |
// MAKE ANY EDITS AS NEEDED | |
// ************************************************************* | |
// Use the JS Formatted Bookmarklet below to see if any changes | |
// need to be made in accordance to the page you want to use | |
// it for. After making needed changes ensure that the revised | |
// bookmarklet is condensed before using it in your browser. | |
// For more info on this bookmarklet visit: | |
// https://github.com/isocialPractice/bookmarklets | |
// ************************************************************* | |
// ************************************************************* | |
// ************************JS-FORMATTED************************* | |
javascript: (function () { | |
var answers = document.getElementsByClassName("answer"); | |
var answersLen = answers.length; | |
var votingContainer; | |
for (i = 0; i < answersLen; i++) { | |
votingContainer = answers[i].getElementsByClassName("js-voting-container")[0]; | |
let anchorButton = document.createElement("a"); | |
anchorButton.innerHTML = "| # |"; | |
anchorButton.setAttribute("href", "#" + answers[i].id); | |
anchorButton.style.marginTop = "10px"; | |
anchorButton.style.marginLeft = "12px"; | |
anchorButton.style.color = "gray"; | |
votingContainer.insertAdjacentElement("beforeend", anchorButton); | |
anchorButton.addEventListener("click", function() { | |
setTimeout(function() { | |
/* copy href value to clipboard */ | |
navigator.clipboard.writeText(anchorButton.href); | |
}, 100); | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment