-
-
Save kenoir/3826408 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
// http://jsfiddle.net/AEg9s/ | |
// Boomtown! | |
AirQuotes = { | |
run: function(){ | |
var panel = (function(){ | |
p = document.querySelector("#my-quote-panel"); | |
if (p == null) { | |
p = document.createElement("div"); | |
p.setAttribute("id", "my-quote-panel"); | |
} | |
p.innerHTML = "<h1>Air Quotes</h1>"; | |
p.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;'); | |
return p; | |
})() | |
var quotes = (function(){ | |
var fullText = "" | |
var quoteArray = [] | |
var content = document.querySelectorAll("body > div"); | |
for (var i = 0; i < content.length; i++) { | |
fullText += content[i].textContent + " "; | |
}; | |
quoteArray = fullText.match(/\s\'(.*?)\'[\s|\?]/g).map(function(value) { | |
return value.substring(value.indexOf("'") + 1, value.lastIndexOf("'")); | |
}); | |
return quoteArray; | |
})() | |
var insert = function(quotes,panel){ | |
quotes.forEach(function(word, index, array) { | |
if (array.indexOf(word) == index) { | |
panel.innerHTML += '<p style="margin:1em 1em;float:left;">' + word + "</p>"; | |
} | |
}); | |
document.body.insertBefore(panel, document.body.firstChild); | |
} | |
insert(quotes,panel) | |
} | |
} | |
AirQuotes.run() | |
// Bookmarklet JS | |
// Converted by: http://chris.zarate.org/bookmarkleter | |
/* | |
javascript:(function(){AirQuotes={run:function(){var%20panel=(function(){p=document.querySelector(%22%23my-quote-panel%22);if(p==null){p=document.createElement(%22div%22);p.setAttribute(%22id%22,%22my-quote-panel%22);}p.innerHTML=%22%3Ch1%3EAir%20Quotes%3C/h1%3E%22;p.setAttribute(%22style%22,'position:relative;padding:10px;border-bottom:1px%20solid%20%23008800;background:%23fff;color:%23333;z-index:1000;font-size:16px;clear:both;overflow:hidden;');return%20p;})()var%20quotes=(function(){var%20fullText=%22%22var%20quoteArray=[]var%20content=document.querySelectorAll(%22body%20%3E%20div%22);for(var%20i=0;i%20%3C%20content.length;i++){fullText+=content[i].textContent+%22%20%22;};quoteArray=fullText.match(/\s\'(.*%3F)\'[\s|\%3F]/g).map(function(value){return%20value.substring(value.indexOf(%22'%22)%20+%201,%20value.lastIndexOf(%22'%22));});return%20quoteArray;})()var%20insert=function(quotes,panel){quotes.forEach(function(word,index,array){if(array.indexOf(word)==index){panel.innerHTML+='%3Cp%20style=%22margin:1em%201em;float:left;%22%3E'+word+%22%3C/p%3E%22;}});document.body.insertBefore(panel,document.body.firstChild);}insert(quotes,panel)}}AirQuotes.run()})(); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment