Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(funcName, baseObj) {
- funcName = funcName || "docReady";
- baseObj = document.getElementById("artcontent");
- var readyList = [];
- var readyFired = false;
- var readyEventHandlersInstalled = false;
- function ready() {
- if (!readyFired) {
- readyFired = true;
- for (var i = 0; i < readyList.length; i++) {
- readyList[i].fn.call(window, readyList[i].ctx);
- }
- readyList = [];
- }
- }
- function readyStateChange() {
- if ( document.readyState === "complete" ) {
- ready();
- }
- }
- baseObj[funcName] = function(callback, context) {
- if (readyFired) {
- setTimeout(function() {callback(context);}, 1);
- return;
- } else {
- readyList.push({fn: callback, ctx: context});
- }
- if (document.readyState === "complete") {
- setTimeout(ready, 1);
- } else if (!readyEventHandlersInstalled) {
- if (document.addEventListener) {
- document.addEventListener("DOMContentLoaded", ready, false);
- window.addEventListener("load", ready, false);
- } else {
- document.attachEvent("onreadystatechange", readyStateChange);
- window.attachEvent("onload", ready);
- }
- readyEventHandlersInstalled = true;
- }
- }
- })("docReady", window);
- docReady(function(){
- var dat = <?=json_encode($links)?>;
- dat.forEach(function(lv){
- if(lv.word instanceof Array) {
- lv.word = lv.word.join('|');
- }
- var expr = new RegExp('(?!<a.*>.*)('+lv.word+')(?!.*</a >)', 'gim');
- document.body.innerHTML = document.body.innerHTML.replace(expr, '<a target="_blank" href="'+lv.link+'?aff=28">$1</a>');
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement