Advertisement
jefrialdi33

Untitled

May 7th, 2020
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*<--------SynTaX HighLightinG By 4LF45T-------->*/
  2. /*===============================================*/
  3. /*Name          :Syntax Highlighting             */
  4. jefrix4lf45t(document.getElementById("4LF45T"));
  5. /*jika anda melihat kode ini,please ya ngentod jangan di copas>:( */
  6. function jefrix4lf45t(elmnt, mode) {
  7.   var lang = (mode || "html");
  8.   var elmntObj = (document.getElementById(elmnt) || elmnt);
  9.   var elmntTxt = elmntObj.innerHTML;
  10.   var tagcolor = "#F9A041"; /*orange*/
  11.   var tagnamecolor = "#28D93E"; /*hijau*/
  12.   var attributecolor = "#28D93E"; /*hijau*/
  13.   var attributevaluecolor = "#F9A041"; /*orange text/css property*/
  14.   var commentcolor = "#C6C6C6"; /*koment*/
  15.   var cssselectorcolor = "#E8EB00"; /*css judul per tag*/ /*kuning*/
  16.   var csspropertycolor = "#EA4061"; /*merah*/ /*property*/
  17.   var csspropertyvaluecolor = "#E8EB00";    /*kuning*/
  18.   var cssdelimitercolor = "#EA4061"; /*merah*/
  19.   var cssimportantcolor = "#C6C6C6";  /*abu-abu*/
  20.   var jscolor = "#F9A041";  /*orange*/
  21.   var jskeywordcolor = "#28D93E";   /*hijau*/
  22.   var jsstringcolor = "#E8EB00";    /*kuning*/
  23.   var jsnumbercolor = "#EA4061";    /*merah*/
  24.   var jspropertycolor = "#F9A041"; /*orange*/
  25.   elmntObj.style.fontFamily = "Consolas,'Courier New', monospace";  /*font face*/
  26.   if (!lang) {lang = "html"; }
  27.   if (lang == "html") {elmntTxt = htmlMode(elmntTxt);}
  28.   if (lang == "css") {elmntTxt = cssMode(elmntTxt);}
  29.   if (lang == "js") {elmntTxt = jsMode(elmntTxt);}
  30.   elmntObj.innerHTML = elmntTxt;
  31.  
  32.   function extract(str, start, end, func, repl) {
  33.     var s, e, d = "", a = [];
  34.     while (str.search(start) > -1) {
  35.       s = str.search(start);
  36.       e = str.indexOf(end, s);
  37.       if (e == -1) {e = str.length;}
  38.       if (repl) {
  39.         a.push(func(str.substring(s, e + (end.length))));      
  40.         str = str.substring(0, s) + repl + str.substr(e + (end.length));
  41.       } else {
  42.         d += str.substring(0, s);
  43.         d += func(str.substring(s, e + (end.length)));
  44.         str = str.substr(e + (end.length));
  45.       }
  46.     }
  47.     this.rest = d + str;
  48.     this.arr = a;
  49.   }
  50.   /*html mode*/
  51.   function htmlMode(txt) {
  52.     var rest = txt, done = "", php, comment, angular, startpos, endpos, note, i;
  53.     comment = new extract(rest, "&lt;!--", "--&gt;", commentMode, "W3HTMLCOMMENTPOS");
  54.     rest = comment.rest;
  55.     while (rest.indexOf("&lt;") > -1) {
  56.       note = "";
  57.       startpos = rest.indexOf("&lt;");
  58.       if (rest.substr(startpos, 9).toUpperCase() == "&LT;STYLE") {note = "css";}
  59.       if (rest.substr(startpos, 10).toUpperCase() == "&LT;SCRIPT") {note = "javascript";}        
  60.       endpos = rest.indexOf("&gt;", startpos);
  61.       if (endpos == -1) {endpos = rest.length;}
  62.       done += rest.substring(0, startpos);
  63.       done += tagMode(rest.substring(startpos, endpos + 4));
  64.       rest = rest.substr(endpos + 4);
  65.       if (note == "css") {
  66.         endpos = rest.indexOf("&lt;/style&gt;");
  67.         if (endpos > -1) {
  68.           done += cssMode(rest.substring(0, endpos));
  69.           rest = rest.substr(endpos);
  70.         }
  71.       }
  72.       if (note == "javascript") {
  73.         endpos = rest.indexOf("&lt;/script&gt;");       /*loh semua kontol*/
  74.         if (endpos > -1) {
  75.           done += jsMode(rest.substring(0, endpos));
  76.           rest = rest.substr(endpos);
  77.         }
  78.       }
  79.     }
  80.     rest = done + rest;
  81.     for (i = 0; i < comment.arr.length; i++) {
  82.         rest = rest.replace("W3HTMLCOMMENTPOS", comment.arr[i]);
  83.     }
  84.     return rest;
  85.   }
  86.   /*end html mode*/
  87.   /*tag &lt; dan &gt; mode*/
  88.   function tagMode(txt) {
  89.     var rest = txt, done = "", startpos, endpos, result;
  90.     while (rest.search(/(\s|<br>)/) > -1) {    
  91.       startpos = rest.search(/(\s|<br>)/);
  92.       endpos = rest.indexOf("&gt;");
  93.       if (endpos == -1) {endpos = rest.length;}
  94.       done += rest.substring(0, startpos);
  95.       done += attributeMode(rest.substring(startpos, endpos));
  96.       rest = rest.substr(endpos);
  97.     }
  98.     result = done + rest;
  99.     result = "<span style=color:" + tagcolor + ">&lt;</span>" + result.substring(4);
  100.     if (result.substr(result.length - 4, 4) == "&gt;") {
  101.       result = result.substring(0, result.length - 4) + "<span style=color:" + tagcolor + ">&gt;</span>";
  102.     }
  103.     return "<span style=color:" + tagnamecolor + ">" + result + "</span>";
  104.   }
  105.   /*end tag &lt; dan &gt; mode*/
  106.   /*attribut mode*/
  107.   function attributeMode(txt) {
  108.     var rest = txt, done = "", startpos, endpos, singlefnuttpos, doublefnuttpos, spacepos;
  109.     while (rest.indexOf("=") > -1) {
  110.       endpos = -1;
  111.       startpos = rest.indexOf("=");
  112.       singlefnuttpos = rest.indexOf("'", startpos);
  113.       doublefnuttpos = rest.indexOf('"', startpos);
  114.       spacepos = rest.indexOf(" ", startpos + 2);
  115.       if (spacepos > -1 && (spacepos < singlefnuttpos || singlefnuttpos == -1) && (spacepos < doublefnuttpos || doublefnuttpos == -1)) {
  116.         endpos = rest.indexOf(" ", startpos);      
  117.       } else if (doublefnuttpos > -1 && (doublefnuttpos < singlefnuttpos || singlefnuttpos == -1) && (doublefnuttpos < spacepos || spacepos == -1)) {
  118.         endpos = rest.indexOf('"', rest.indexOf('"', startpos) + 1);
  119.       } else if (singlefnuttpos > -1 && (singlefnuttpos < doublefnuttpos || doublefnuttpos == -1) && (singlefnuttpos < spacepos || spacepos == -1)) {
  120.         endpos = rest.indexOf("'", rest.indexOf("'", startpos) + 1);
  121.       }
  122.       if (!endpos || endpos == -1 || endpos < startpos) {endpos = rest.length;}
  123.       done += rest.substring(0, startpos);
  124.       done += attributeValueMode(rest.substring(startpos, endpos + 1));
  125.       rest = rest.substr(endpos + 1);
  126.     }
  127.     return "<span style=color:" + attributecolor + ">" + done + rest + "</span>";
  128.   }
  129.   /*end attribut mode*/
  130.   function attributeValueMode(txt) {
  131.     return "<span style=color:" + attributevaluecolor + ">" + txt + "</span>";
  132.   }
  133.   function commentMode(txt) {
  134.     return "<span style=color:" + commentcolor + ">" + txt + "</span>";
  135.   }
  136.   function cssMode(txt) {
  137.     var rest = txt, done = "", s, e, comment, i, midz, c, cc;
  138.     comment = new extract(rest, /\/\*/, "*/", commentMode, "W3CSSCOMMENTPOS");
  139.     rest = comment.rest;
  140.     while (rest.search("{") > -1) {
  141.       s = rest.search("{");
  142.       midz = rest.substr(s + 1);
  143.       cc = 1;
  144.       c = 0;
  145.       for (i = 0; i < midz.length; i++) {
  146.         if (midz.substr(i, 1) == "{") {cc++; c++}
  147.         if (midz.substr(i, 1) == "}") {cc--;}
  148.         if (cc == 0) {break;}
  149.       }
  150.       if (cc != 0) {c = 0;}
  151.       e = s;
  152.       for (i = 0; i <= c; i++) {
  153.         e = rest.indexOf("}", e + 1);
  154.       }
  155.       if (e == -1) {e = rest.length;}
  156.       done += rest.substring(0, s + 1);
  157.       done += cssPropertyMode(rest.substring(s + 1, e));
  158.       rest = rest.substr(e);
  159.     }
  160.     rest = done + rest;
  161.     rest = rest.replace(/{/g, "<span style=color:" + cssdelimitercolor + ">{</span>");
  162.     rest = rest.replace(/}/g, "<span style=color:" + cssdelimitercolor + ">}</span>");
  163.     for (i = 0; i < comment.arr.length; i++) {
  164.         rest = rest.replace("W3CSSCOMMENTPOS", comment.arr[i]);
  165.     }
  166.     return "<span style=color:" + cssselectorcolor + ">" + rest + "</span>";
  167.   }
  168.   function cssPropertyMode(txt) {
  169.     var rest = txt, done = "", s, e, n, loop;
  170.     if (rest.indexOf("{") > -1 ) { return cssMode(rest); }
  171.     while (rest.search(":") > -1) {
  172.       s = rest.search(":");
  173.       loop = true;
  174.       n = s;
  175.       while (loop == true) {
  176.         loop = false;
  177.         e = rest.indexOf(";", n);
  178.         if (rest.substring(e - 5, e + 1) == "&nbsp;") {
  179.           loop = true;
  180.           n = e + 1;
  181.         }
  182.       }
  183.       if (e == -1) {e = rest.length;}
  184.       done += rest.substring(0, s);
  185.       done += cssPropertyValueMode(rest.substring(s, e + 1));
  186.       rest = rest.substr(e + 1);
  187.     }
  188.     return "<span style=color:" + csspropertycolor + ">" + done + rest + "</span>";
  189.   }
  190.   function cssPropertyValueMode(txt) {
  191.     var rest = txt, done = "", s;
  192.     rest = "<span style=color:" + cssdelimitercolor + ">:</span>" + rest.substring(1);
  193.     while (rest.search(/!important/i) > -1) {
  194.       s = rest.search(/!important/i);
  195.       done += rest.substring(0, s);
  196.       done += cssImportantMode(rest.substring(s, s + 10));
  197.       rest = rest.substr(s + 10);
  198.     }
  199.     result = done + rest;    
  200.     if (result.substr(result.length - 1, 1) == ";" && result.substr(result.length - 6, 6) != "&nbsp;" && result.substr(result.length - 4, 4) != "&lt;" && result.substr(result.length - 4, 4) != "&gt;" && result.substr(result.length - 5, 5) != "&amp;") {
  201.       result = result.substring(0, result.length - 1) + "<span style=color:" + cssdelimitercolor + ">;</span>";
  202.     }
  203.     return "<span style=color:" + csspropertyvaluecolor + ">" + result + "</span>";
  204.   }
  205.   function cssImportantMode(txt) {
  206.     return "<span style=color:" + cssimportantcolor + ";font-weight:bold;>" + txt + "</span>";
  207.   }
  208.   function jsMode(txt) {
  209.     var rest = txt, done = "", esc = [], i, cc, tt = "", sfnuttpos, dfnuttpos, compos, comlinepos, keywordpos, numpos, mypos, dotpos, y;
  210.     for (i = 0; i < rest.length; i++)  {
  211.       cc = rest.substr(i, 1);
  212.       if (cc == "\\") {
  213.         esc.push(rest.substr(i, 2));
  214.         cc = "W3JSESCAPE";
  215.         i++;
  216.       }
  217.       tt += cc;
  218.     }
  219.     rest = tt;
  220.     y = 1;
  221.     while (y == 1) {
  222.       sfnuttpos = getPos(rest, "'", "'", jsStringMode);
  223.       dfnuttpos = getPos(rest, '"', '"', jsStringMode);
  224.       compos = getPos(rest, /\/\*/, "*/", commentMode);
  225.       comlinepos = getPos(rest, /\/\//, "<br>", commentMode);      
  226.       numpos = getNumPos(rest, jsNumberMode);
  227.       keywordpos = getKeywordPos("js", rest, jsKeywordMode);
  228.       dotpos = getDotPos(rest, jsPropertyMode);
  229.       if (Math.max(numpos[0], sfnuttpos[0], dfnuttpos[0], compos[0], comlinepos[0], keywordpos[0], dotpos[0]) == -1) {break;}
  230.       mypos = getMinPos(numpos, sfnuttpos, dfnuttpos, compos, comlinepos, keywordpos, dotpos);
  231.       if (mypos[0] == -1) {break;}
  232.       if (mypos[0] > -1) {
  233.         done += rest.substring(0, mypos[0]);
  234.         done += mypos[2](rest.substring(mypos[0], mypos[1]));
  235.         rest = rest.substr(mypos[1]);
  236.       }
  237.     }
  238.     rest = done + rest;
  239.     for (i = 0; i < esc.length; i++) {
  240.       rest = rest.replace("W3JSESCAPE", esc[i]);
  241.     }
  242.     return "<span style=color:" + jscolor + ">" + rest + "</span>";
  243.   }
  244.   function jsStringMode(txt) {
  245.     return "<span style=color:" + jsstringcolor + ">" + txt + "</span>";
  246.   }
  247.   function jsKeywordMode(txt) {
  248.     return "<span style=color:" + jskeywordcolor + ">" + txt + "</span>";
  249.   }
  250.   function jsNumberMode(txt) {
  251.     return "<span style=color:" + jsnumbercolor + ">" + txt + "</span>";
  252.   }
  253.   function jsPropertyMode(txt) {
  254.     return "<span style=color:" + jspropertycolor + ">" + txt + "</span>";
  255.   }
  256.   function getDotPos(txt, func) {
  257.     var x, i, j, s, e, arr = [".","<", " ", ";", "(", "+", ")", "[", "]", ",", "&", ":", "{", "}", "/" ,"-", "*", "|", "%"];
  258.     s = txt.indexOf(".");
  259.     if (s > -1) {
  260.       x = txt.substr(s + 1);
  261.       for (j = 0; j < x.length; j++) {
  262.         cc = x[j];
  263.         for (i = 0; i < arr.length; i++) {
  264.           if (cc.indexOf(arr[i]) > -1) {
  265.             e = j;
  266.             return [s + 1, e + s + 1, func];
  267.           }
  268.         }
  269.       }
  270.     }
  271.     return [-1, -1, func];
  272.   }
  273.   function getMinPos() {
  274.     var i, arr = [];
  275.     for (i = 0; i < arguments.length; i++) {
  276.       if (arguments[i][0] > -1) {
  277.         if (arr.length == 0 || arguments[i][0] < arr[0]) {arr = arguments[i];}
  278.       }
  279.     }
  280.     if (arr.length == 0) {arr = arguments[i];}
  281.     return arr;
  282.   }
  283.   function getKeywordPos(typ, txt, func) {
  284.     var words, i, pos, rpos = -1, rpos2 = -1, patt;
  285.     if (typ == "js") {
  286.       words = ["abstract","arguments","boolean","break","byte","case","catch","char","class","const","continue","debugger","default","delete",
  287.       "do","double","else","enum","eval","export","extends","false","final","finally","float","for","function","goto","if","implements","import",
  288.       "in","instanceof","int","interface","let","long","NaN","native","new","null","package","private","protected","public","return","short","static",
  289.       "super","switch","synchronized","this","throw","throws","transient","true","try","typeof","var","void","volatile","while","with","yield"];
  290.     }
  291.     for (i = 0; i < words.length; i++) {
  292.       pos = txt.indexOf(words[i]);
  293.       if (pos > -1) {
  294.         patt = /\W/g;
  295.         if (txt.substr(pos + words[i].length,1).match(patt) && txt.substr(pos - 1,1).match(patt)) {
  296.           if (pos > -1 && (rpos == -1 || pos < rpos)) {
  297.             rpos = pos;
  298.             rpos2 = rpos + words[i].length;
  299.           }
  300.         }
  301.       }
  302.     }
  303.     return [rpos, rpos2, func];
  304.   }
  305.   function getPos(txt, start, end, func) {
  306.     var s, e;
  307.     s = txt.search(start);
  308.     e = txt.indexOf(end, s + (end.length));
  309.     if (e == -1) {e = txt.length;}
  310.     return [s, e + (end.length), func];
  311.   }
  312.   function getNumPos(txt, func) {
  313.     var arr = ["<br>", " ", ";", "(", "+", ")", "[", "]", ",", "&", ":", "{", "}", "/" ,"-", "*", "|", "%", "="], i, j, c, startpos = 0, endpos, word;
  314.     for (i = 0; i < txt.length; i++) {
  315.       for (j = 0; j < arr.length; j++) {
  316.         c = txt.substr(i, arr[j].length);
  317.         if (c == arr[j]) {
  318.           if (c == "-" && (txt.substr(i - 1, 1) == "e" || txt.substr(i - 1, 1) == "E")) {
  319.             continue;
  320.           }
  321.           endpos = i;
  322.           if (startpos < endpos) {
  323.             word = txt.substring(startpos, endpos);
  324.             if (!isNaN(word)) {return [startpos, endpos, func];}
  325.           }
  326.           i += arr[j].length;
  327.           startpos = i;
  328.           i -= 1;
  329.           break;
  330.         }
  331.       }
  332.     }  
  333.     return [-1, -1, func];
  334.     /*menagkhiri*/
  335.   }  
  336. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement