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> to 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://**
// @version 0.1
// ==/UserScript==

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

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 "" to <user>
for (i = 0; i < links.snapshotLength; i++) {
if ( links.snapshotItem(i).href.indexOf("") != -1 )
links.snapshotItem(i).href = links.snapshotItem(i).href.replace("", user + "");
}, true);

Install Google Pages Static Files script ( | mirror)

No comments: