Advertisement
adf1969

Bitrix24 - LocalExplorer Helper

Mar 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Bitrix - Local Explorer Helper
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        https://*.bitrix24.site/*
  8. // @match        https://avcorp.bitrix24.com/*
  9. // @match        https://docs.google.com/*
  10. // //@match        https://avcorp.bitrix24.com/company/personal/user/1/tasks/task/view/71/*
  11. // @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  12. // @require      https://gist.github.com/raw/2625891/waitForKeyElements.js
  13. // @grant        GM_addStyle
  14. // ==/UserScript==
  15.  
  16. 'use strict';
  17. //waitForKeyElements('#workarea', processReplace);
  18. //waitForKeyElements('#pagetitle', processTextNodes);
  19. waitForKeyElements('.page-header', prefixUrls);
  20. waitForKeyElements('.crm-iframe-popup', prefixUrls);
  21. waitForKeyElements('.task-iframe-popup', prefixUrls);
  22.  
  23.  
  24. function prefixUrls() {
  25.     var links = document.getElementsByTagName('a');
  26.     var dletter = '';
  27.     for (var i = 0; i < links.length; i++) {
  28.         console.log(i, links[i].href);
  29.         if (/^file:\/\/\/.*/.test(links[i].href)) {
  30.             debugger;
  31.             console.log(">>>Found file:/// Match. Replace with localexplorer:");
  32.             links[i].href = links[i].href.replace("file:///", "localexplorer:");
  33.             links[i].target = "_self";
  34.         }
  35.         //if (/^http:\/\/[A-Za-z]:\\.*/.test(links[i].href)) {
  36.         // test for http://[letter]
  37.         if (/^http:\/\/[A-Za-z]$/.test(links[i].origin)) {
  38.             debugger;
  39.             console.log(">>>Found http://[A-Z]:\ Match. Replace http:// with localexplorer:");
  40.             dletter = links[i].origin.slice(-1);
  41.             links[i].href = "localexplorer:" + dletter + ':' + links[i].pathname;
  42.             //links[i].href = links[i].href.replace("http://", "localexplorer:" + dletter + ':');
  43.             //links[i].href = links[i].href +  + links[i].pathname
  44.             links[i].href = links[i].href.replace("/", "\\");
  45.             links[i].target = "_self";
  46.         }
  47.     }
  48. }
  49.  
  50. // See: https://stackoverflow.com/questions/24417791/replace-many-text-terms-using-tampermonkey-without-affecting-urls-and-not-look
  51. function processTextNodes() {
  52.     var replaceArray = [
  53.         [/Deals/gi, 'Cases'],
  54.         [/Deal/gi, 'Case'],
  55.         [/deal/gi, 'case'],
  56.         [/DEAL/gi, 'CASE'],
  57.         [/DEALS/gi, 'CASES'],
  58.         // etc.
  59.  
  60.     ];
  61.  
  62.     //debugger;
  63.     replaceTextNodes(replaceArray);
  64. }
  65.  
  66. function replaceTextNodes(replaceArray) {
  67.     var numTerms    = replaceArray.length;
  68.     var txtWalker   = document.createTreeWalker (
  69.         document.body,
  70.         NodeFilter.SHOW_TEXT,
  71.         {   acceptNode: function (node) {
  72.             //-- Skip whitespace-only nodes
  73.             if (node.nodeValue.trim() )
  74.                 return NodeFilter.FILTER_ACCEPT;
  75.  
  76.             return NodeFilter.FILTER_SKIP;
  77.         }
  78.         },
  79.         false
  80.     );
  81.     var txtNode     = null;
  82.  
  83.     while (txtNode  = txtWalker.nextNode () ) {
  84.         var oldTxt  = txtNode.nodeValue;
  85.  
  86.         for (var J  = 0;  J < numTerms;  J++) {
  87.             oldTxt  = oldTxt.replace (replaceArray[J][0], replaceArray[J][1]);
  88.         }
  89.         txtNode.nodeValue = oldTxt;
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement