Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function(funcName, baseObj) {
  2.     funcName = funcName || "docReady";
  3.     baseObj = document.getElementById("artcontent");
  4.     var readyList = [];
  5.     var readyFired = false;
  6.     var readyEventHandlersInstalled = false;
  7.     function ready() {
  8.         if (!readyFired) {
  9.             readyFired = true;
  10.             for (var i = 0; i < readyList.length; i++) {
  11.                 readyList[i].fn.call(window, readyList[i].ctx);
  12.             }
  13.             readyList = [];
  14.         }
  15.     }
  16.     function readyStateChange() {
  17.         if ( document.readyState === "complete" ) {
  18.             ready();
  19.         }
  20.     }
  21.     baseObj[funcName] = function(callback, context) {
  22.         if (readyFired) {
  23.             setTimeout(function() {callback(context);}, 1);
  24.             return;
  25.         } else {
  26.             readyList.push({fn: callback, ctx: context});
  27.         }
  28.         if (document.readyState === "complete") {
  29.             setTimeout(ready, 1);
  30.         } else if (!readyEventHandlersInstalled) {
  31.             if (document.addEventListener) {
  32.                 document.addEventListener("DOMContentLoaded", ready, false);
  33.                 window.addEventListener("load", ready, false);
  34.             } else {
  35.                 document.attachEvent("onreadystatechange", readyStateChange);
  36.                 window.attachEvent("onload", ready);
  37.             }
  38.             readyEventHandlersInstalled = true;
  39.         }
  40.     }
  41. })("docReady", window);
  42. docReady(function(){
  43.   var dat = <?=json_encode($links)?>;
  44.     dat.forEach(function(lv){
  45.         if(lv.word instanceof Array) {
  46.             lv.word = lv.word.join('|');
  47.         }
  48.         var expr = new RegExp('(?!<a.*>.*)('+lv.word+')(?!.*</a >)', 'gim');
  49.         document.body.innerHTML = document.body.innerHTML.replace(expr, '<a target="_blank" href="'+lv.link+'?aff=28">$1</a>');        
  50.     });
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement