Wednesday, February 14, 2007

Google Pages Static Link rewriter script

On my Google Pages site, the links to my uploaded files suddenly stopped working. They changed from http://<myusername>.googlepages.com/theFile.ext to http://pages.google.com/-/static_files/theFile.ext where they would give me a 404 Not Found Error. This script is devoted to changing the links back so I can access my files.


// ==UserScript==
// @name Google Pages Static Files
// @description Rewrite "static files" on GooglePages to point to correct locations
// @include http://*.googlepages.com/*
// @version 0.1
// ==/UserScript==


//Get googlepages user to use in rewriting the links
var user = window.location.href.split(".")[0].replace("http://", "");


window.addEventListener('load',
function() {
//Use XPath to find all <a> elements with href attrib
var links = document.evaluate('//a[@href]',document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);


//Rewrite all links with "http://pages.google.com/-/static_files" to <user>.googlepages.com
for (i = 0; i < links.snapshotLength; i++) {
if ( links.snapshotItem(i).href.indexOf("http://pages.google.com/-/static_files") != -1 )
links.snapshotItem(i).href = links.snapshotItem(i).href.replace("pages.google.com/-/static_files", user + ".googlepages.com");
}
}, true);

Install Google Pages Static Files script (userscripts.org | mirror)

No comments: