Created
October 2, 2012 23:34
-
-
Save ryangadams/3823998 to your computer and use it in GitHub Desktop.
A js bookmarklet to extract the words on news websites that are 'quoted'.
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
var myPanel = document.querySelector("#my-quote-panel"); | |
if (myPanel == null) { | |
myPanel = document.createElement("div"); | |
myPanel.setAttribute("id", "my-quote-panel"); | |
} | |
myPanel.innerHTML = "<h1>Air Quotes</h1>"; | |
myPanel.setAttribute("style", 'position:relative;padding:10px;border-bottom:1px solid #008800;background:#fff;color:#333;z-index:1000;font-size:16px;clear:both;overflow:hidden;'); | |
document.body.insertBefore(myPanel, document.body.firstChild); | |
var fullContent = ""; | |
var content = document.querySelectorAll("body > div"); | |
for (var i = 0; i < content.length; i++) { | |
fullContent += content[i].textContent + " "; | |
}; | |
fullContent.match(/\s\'(.*?)\'[\s|\?]/g).map(function(value) { | |
return value.substring(value.indexOf("'") + 1, value.lastIndexOf("'")); | |
}).forEach(function(word, index, array) { | |
if (array.indexOf(word) == index) { | |
myPanel.innerHTML += '<p style="margin:1em 1em;float:left;">' + word + "</p>"; | |
} | |
}); | |
// bookmarklet text | |
// create a new bookmarklet with this as the location | |
// javascript:var%20myPanel%20=%20document.querySelector(%22#my-quote-panel%22);if%20(myPanel%20==%20null)%20{myPanel%20=%20document.createElement(%22div%22);myPanel.setAttribute(%22id%22,%20%22my-quote-panel%22);}myPanel.innerHTML%20=%20%22<h1>Air%20Quotes</h1>%22;myPanel.setAttribute(%22style%22,%20%27position:relative;padding:10px;border-bottom:1px%20solid%20#008800;background:#fff;color:#333;z-index:1000;font-size:16px;clear:both;overflow:hidden;%27);document.body.insertBefore(myPanel,%20document.body.firstChild);var%20fullContent%20=%20%22%22;var%20content%20=%20document.querySelectorAll(%22body%20>%20div%22);for%20(var%20i%20=%200;%20i%20<%20content.length;%20i++)%20{fullContent%20+=%20content[i].textContent%20+%20%22%20%22;};fullContent.match(/\s\%27(.*?)\%27[\s|\?]/g).map(function(value)%20{return%20value.substring(value.indexOf(%22%27%22)%20+%201,%20value.lastIndexOf(%22%27%22));}).forEach(function(word,%20index,%20array)%20{if%20(array.indexOf(word)%20==%20index)%20{myPanel.innerHTML%20+=%20%27<p%20style=%22margin:1em%201em;float:left;%22>%27%20+%20word%20+%20%22</p>%22;}}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment