Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Bitrix - Local Explorer Helper
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author You
- // @match https://*.bitrix24.site/*
- // @match https://avcorp.bitrix24.com/*
- // @match https://docs.google.com/*
- // //@match https://avcorp.bitrix24.com/company/personal/user/1/tasks/task/view/71/*
- // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
- // @require https://gist.github.com/raw/2625891/waitForKeyElements.js
- // @grant GM_addStyle
- // ==/UserScript==
- 'use strict';
- //waitForKeyElements('#workarea', processReplace);
- //waitForKeyElements('#pagetitle', processTextNodes);
- waitForKeyElements('.page-header', prefixUrls);
- waitForKeyElements('.crm-iframe-popup', prefixUrls);
- waitForKeyElements('.task-iframe-popup', prefixUrls);
- function prefixUrls() {
- var links = document.getElementsByTagName('a');
- var dletter = '';
- for (var i = 0; i < links.length; i++) {
- console.log(i, links[i].href);
- if (/^file:\/\/\/.*/.test(links[i].href)) {
- debugger;
- console.log(">>>Found file:/// Match. Replace with localexplorer:");
- links[i].href = links[i].href.replace("file:///", "localexplorer:");
- links[i].target = "_self";
- }
- //if (/^http:\/\/[A-Za-z]:\\.*/.test(links[i].href)) {
- // test for http://[letter]
- if (/^http:\/\/[A-Za-z]$/.test(links[i].origin)) {
- debugger;
- console.log(">>>Found http://[A-Z]:\ Match. Replace http:// with localexplorer:");
- dletter = links[i].origin.slice(-1);
- links[i].href = "localexplorer:" + dletter + ':' + links[i].pathname;
- //links[i].href = links[i].href.replace("http://", "localexplorer:" + dletter + ':');
- //links[i].href = links[i].href + + links[i].pathname
- links[i].href = links[i].href.replace("/", "\\");
- links[i].target = "_self";
- }
- }
- }
- // See: https://stackoverflow.com/questions/24417791/replace-many-text-terms-using-tampermonkey-without-affecting-urls-and-not-look
- function processTextNodes() {
- var replaceArray = [
- [/Deals/gi, 'Cases'],
- [/Deal/gi, 'Case'],
- [/deal/gi, 'case'],
- [/DEAL/gi, 'CASE'],
- [/DEALS/gi, 'CASES'],
- // etc.
- ];
- //debugger;
- replaceTextNodes(replaceArray);
- }
- function replaceTextNodes(replaceArray) {
- var numTerms = replaceArray.length;
- var txtWalker = document.createTreeWalker (
- document.body,
- NodeFilter.SHOW_TEXT,
- { acceptNode: function (node) {
- //-- Skip whitespace-only nodes
- if (node.nodeValue.trim() )
- return NodeFilter.FILTER_ACCEPT;
- return NodeFilter.FILTER_SKIP;
- }
- },
- false
- );
- var txtNode = null;
- while (txtNode = txtWalker.nextNode () ) {
- var oldTxt = txtNode.nodeValue;
- for (var J = 0; J < numTerms; J++) {
- oldTxt = oldTxt.replace (replaceArray[J][0], replaceArray[J][1]);
- }
- txtNode.nodeValue = oldTxt;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement