Created
June 10, 2011 09:11
-
-
Save zentooo/1018528 to your computer and use it in GitHub Desktop.
Replace windows file server path with cifs URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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