Skip to content

Instantly share code, notes, and snippets.

@zentooo
Created June 10, 2011 09:11
Show Gist options
  • Save zentooo/1018528 to your computer and use it in GitHub Desktop.
Save zentooo/1018528 to your computer and use it in GitHub Desktop.
Replace windows file server path with cifs URL
// ==UserScript==
// @id winpath_to_cifs
// @author zentooo
// @name winpath_to_cifs
// @include http://example.com/*
// ==/UserScript==
var textNodes = document.evaluate("/html/body//text()", document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
var textNode = textNodes.iterateNext();
var pussy = [];
function asCifs(textNode) {
var text = textNode.nodeValue;
return text.replace(/\\\\/, "cifs://").replace(/\\/g, "/");
}
while ( textNode ) {
var cifsUrl = asCifs(textNode);
var m = cifsUrl.match(/cifs:\/\/(?:\w+\/)+/);
if ( m ) {
var el = document.createElement("a");
el.innerHTML = " (" + m[0] + ")";
el.href = m[0];
pussy.push( { parent: textNode.parentNode, newEl: el } );
}
textNode = textNodes.iterateNext();
}
pussy.forEach(function(puss) {
puss.parent.appendChild(puss.newEl);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment