You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
misc/greasemonkey/reverted_pim_links.user.js

140 lines
5.3 KiB

// ==UserScript==
// @name reverted PIM links
// @namespace Utopiah
// @description overlay so that a visited page indexed in a PIM displays a link back
// @include *
// @exclude *://mail.google.com/mail/*
// ==/UserScript==
/*
* Script homepage : http://fabien.benetou.fr/Tools/Greasemonkey#RevertedPIMLinks
*
* todo
* generate the data store on demand
* check link_extractor/revertingpimlinks.sh
*
* add links to the database
* note that date is optional but the source is not
* delicious-20100730.htm
* emails
* apply to Person/ cf earlier idea Seedea:Oimp/Socialannotating
* IRC/IM
34269 links using
for SCANNETWORK in $(ls ~/irclogs/); do grep http ~/irclogs/$SCANNETWORK/* | sed "s/.* <\(.*\)> .*http\(.*\)/http\2 \1 on $SCANNETWORK/"; done | wc -l
19881 freenode
5834 blinkenshell
4867 testing
2354 seedeabitlbee
1325 mozilla
7 rezosup
for SCANNETWORK in $(ls ~/irclogs/); do echo -n -e "$SCANNETWORK\t" && grep http ~/irclogs/$SCANNETWORK/* | sed "s/.* <\(.*\)> .*http\(.*\)/http\2 \1 on $SCANNETWORK/" | wc -l; done | awk '{print $2 "\t" $1}' | sort -n -r
*
*/
String.prototype.ColorHash = function(){
// from http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
var hash = 0;
if (this.length == 0) return hash;
for (i = 0; i < this.length; i++) {
char = this.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
hash = Math.round(Math.sqrt(Math.abs(hash))); // How to convert to 16bit integer?
return hash;
// suppose to send back a correct HTML color value
}
// configuration
var script_name = "rPIMlinks";
var PIM_URL = "http://fabien.benetou.fr/";
// actual script
//load URLs in data store (greasemonkey.scriptvals in about:config in prefs.js)
// load the entire set of links
// merging linksloaded_prefs.js to prefs.js
// C:\Documents and Settings\tyflser\Application Data\Mozilla\Firefox\Profiles\aosia15p.default
// e.g. user_pref("greasemonkey.scriptvals.Utopiah/reverted PIM links.rPIMlinks http://www.wikipedia.com/wiki/Simulacra_and_Simulation", "ReadingNotes/LeSpectateurEmancipe");
//everytime a page is loaded
//get the current URL
PIMpages = GM_getValue(script_name+" "+document.URL,"fail");
PIMpages_date = GM_getValue(script_name+" date","fail");
//if the current URL is in data store
if (PIMpages != "fail")
{
//display link
var pages = PIMpages.split(" ");
var myDiv = document.createElement('div');
myDiv.id = "GM_PIM_Window";
while (page = pages.shift()){
grouppage = page.split(".");
group = grouppage[0];
page = grouppage[1];
myDiv.innerHTML += "<p class=\"GM_PIM_link\">"
+"<a href=\""+PIM_URL+group+"/"+page+"\">"
+"<font color=\""+group.ColorHash()+"\">"+group+"</font>/"
+"<font color=\"white\">"+page+"</font>/"
+"</a>"
+"<sup><a href=\""+PIM_URL+page+"?action=edit\">[e]</a></sup>"
+"</p>";
}
boxcss = 'position:fixed; right:5px; top:5px; background-color:black; z-index:1; opacity:0.7;';
boxcss += 'padding:2px; margin:1px;';
boxcss += 'color:blue; font-size:10px; text-align:right;';
boxcss += 'border-width:3px; border-color:gray; border-style:solid;';
myDiv.style.cssText = boxcss;
myDiv.style.cssText += ' line-height:1px;';
myDiv.innerHTML += "<hr/><p style='font-size:8px; line-height:10px;' class='GM_PIM_ref'><a href='http://fabien.benetou.fr/Tools/Greasemonkey#RevertedPIMLinks'>RevertedPIMLinks</a></p>";
myDiv.innerHTML += "<p style='float:left;line-height:10px;' class='GM_PIM_ref' onclick=\"document.getElementById('GM_PIM_Window').style.visibility='hidden';document.getElementById('GM_PIM_Folded_Window').style.visibility='visible';\">&gt;&gt;</p><br/>";
if (PIMpages_date != "fail")
{
myDiv.innerHTML += "<p> (date:"+PIMpages_date+")</p>";
}
document.body.appendChild(myDiv);
var myFoldedDiv = document.createElement('div');
myFoldedDiv.id = "GM_PIM_Folded_Window";
myFoldedDiv.innerHTML += "<p style='float:left;' class='GM_PIM_ref' onclick=\"document.getElementById('GM_PIM_Window').style.visibility='visible';document.getElementById('GM_PIM_Folded_Window').style.visibility='hidden';\">&lt;&lt;</p>";
myFoldedDiv.style.cssText = boxcss;
myFoldedDiv.style.cssText += "visibility:hidden;";
myFoldedDiv.style.cssText += "line-height:10px;";
document.body.appendChild(myFoldedDiv);
}
function shortcuts (e){
switch(e.charCode)
{
case "u".charCodeAt(0) : document.getElementById('GM_PIM_Window').style.visibility='visible';document.getElementById('GM_PIM_Folded_Window').style.visibility='hidden'; break;
case "f".charCodeAt(0) : document.getElementById('GM_PIM_Window').style.visibility='hidden';document.getElementById('GM_PIM_Folded_Window').style.visibility='visible'; break;
}
};
function registerShortcuts() {
window.addEventListener("keypress", shortcuts, true);
};
function unregisterShortcuts() {
window.removeEventListener("keypress", shortcuts, true);
};
registerShortcuts();
function registerListener(node) {
node.addEventListener("mouseover", function() {
unregisterShortcuts();
scroll_pause(); }, true);
node.addEventListener("mouseout", function() {
scroll_start ();
registerShortcuts();
}, true);
}