Skip to content

Instantly share code, notes, and snippets.

@dergachev
Last active May 25, 2017 05:43
Show Gist options
  • Save dergachev/6799352 to your computer and use it in GitHub Desktop.
Save dergachev/6799352 to your computer and use it in GitHub Desktop.
Highlight Quotes Bookmarklet
(function(){
var done = false;
var script = document.createElement("script");
script.src = "//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js";
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
doStuff();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
})();
function doStuff() {
var seenArtifacts = [];
var targets = [
".post-text", // "http://www.backupcentral.com/phpBB2"
".posttext" // "http://forum.proxmox.com/archive"
].join(",")
jQuery(targets).contents().filter(function() {
return this.nodeType == 3;
}).each(function() {
var text = this.nodeValue.replace(/\s+/g,'');
if(text.match(/^\s*$/)) {
return;
}
if(indexOfSubstring(seenArtifacts, text) != -1) {
jQuery(this).wrap('<span class="seen" style="background-color:yellow"/>');
}
seenArtifacts.push(text);
});
//console.log(jQuery('.seen'));
function indexOfSubstring(haystack, needle) {
for (i = 0; i < haystack.length; i++) {
if (haystack[i].indexOf(needle) != -1) {
return i;
}
}
return -1;
}
}
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.2/jquery.min.js" ></script>
<script src="http://dergachev.github.io/markleteer/markleteer.js"></script>
<p>To install the bookmarklet, drag the "HighlightQuotes" link to your bookmarks bar. <a target="_blank" href="https://gist.github.com/dergachev/5769111/raw/bbcabdae14eb09bd3e3488314e54299be8317085/installing-bookmarklet.gif">need help with this?</a></p>
<textarea class="bookmarklet" title="HighlightQuotes">
(function () {
var script = document.createElement('script');
script.src = 'https://gist.github.com/dergachev/6799352/raw/highlight-quotes.bookmarklet.js';
script.type = 'text/javascript';
document.body.appendChild(script);
})();
</textarea>
<p>After installing, you can test it on <a href="http://www.backupcentral.com/phpBB2/two-way-mirrors-of-external-mailing-lists-3/backuppc-21/nfs-woes-111237/">backupcentral.com</a>.
<p>Source code at <a target=="_blank" href="https://gist.github.com/dergachev/6799352">https://gist.github.com/dergachev/6799352</a></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment