The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Problem with JS code

2 posters

Go down

Solved Problem with JS code

Post by testyforum September 13th 2019, 7:39 pm

Technical Details


Forum version : #phpBB3
Position : Administrator
Concerned browser(s) : Mozilla Firefox, Google Chrome
Who the problem concerns : All members
When the problem appeared : long ago Smile
Forum link : https://www.darmowybonus.com/

Description of problem

Hello, I have a problem with my JS code. If i open a topic, I have to wait a few seconds. Can I exchange this code for another one? This code converts the text into a link. Maybe it is available other solution changing phrases for links?

Code:
$(function(){
$(".post .postbody").each(function(){
var _1=$(this).html();
var _2=_1.replace(/Bob Casino/gi,"<a target='blank' href='https://www.bobregister.com/refer/71c306cf'>Bob Casino</a>");
$(this).html(_2);
var _1=$(this).html();
var _2=_1.replace(/Melbet/gi,"<a target='blank' href='http://refpahah.xyz/L?tag=d_40498m_2170c_&site=40498&ad=2170/'>Melbet</a>");
$(this).html(_2);
var _1=$(this).html();
var _2=_1.replace(/1xbit/gi,"<a target='blank' href='http://referrer.website/L?tag=d_35028m_1732c_&site=35028&ad=1732'>1xbit</a>");
$(this).html(_2);
});
});

The whole code has ~1200 lines Laughing


Last edited by testyforum on September 14th 2019, 8:49 am; edited 1 time in total
testyforum
testyforum
Forumember

Posts : 25
Reputation : 1
Language : polish / english

http://testyforum.forumpolish.com/forum

Back to top Go down

Solved Re: Problem with JS code

Post by Guest September 13th 2019, 8:51 pm

Hello,

If I understood this right, you want to replace certain text on your forum with links. Your solution is not the most efficient. This one should do the trick and be less lengthy, while also hopefully much faster:
Code:
;var d=document;function _q(e){return d.querySelectorAll(e)};function l(e, ev, c){e.addEventListener(ev, function(f){c(f)})};

var links={
"Bob Casino":"https://www.bobregister.com/refer/71c306cf",
"Melbet":"http://refpahah.xyz/L?tag=d_40498m_2170c_&site=40498&ad=2170",
"1xbit":"http://referrer.website/L?tag=d_35028m_1732c_&site=35028&ad=1732",
};

l(d, 'DOMContentLoaded', function(){
var posts=_q(".postbody .content"), p;
posts.forEach(post=>{
p=post.innerHTML;
Object.entries(links).forEach(item=>{
p=p.replace(new RegExp(item[0], "gi"), "<a href='"+item[1]+"'>"+item[0]+"</a>");
});
post.innerHTML=p;
});
});

You need to modify this part:
Code:
var links={
"Bob Casino":"https://www.bobregister.com/refer/71c306cf",
"Melbet":"http://refpahah.xyz/L?tag=d_40498m_2170c_&site=40498&ad=2170",
"1xbit":"http://referrer.website/L?tag=d_35028m_1732c_&site=35028&ad=1732",
};
For every text=>link transformation you want, you have to add a new line structured like these 3 that I took from your original code. If you want I may be able to do it for you if you post the whole code here.

If the code doesn't work, keep it on your forum and post a link to a topic where it is supposed to do modifications.
avatar
Guest
Guest


Back to top Go down

Solved Re: Problem with JS code

Post by testyforum September 14th 2019, 8:09 am

This is it! Thanks Smile
testyforum
testyforum
Forumember

Posts : 25
Reputation : 1
Language : polish / english

http://testyforum.forumpolish.com/forum

Back to top Go down

Solved Re: Problem with JS code

Post by skouliki September 14th 2019, 8:37 am

When your request is complete, please mark it as Solved.
skouliki
skouliki
Manager
Manager

Female Posts : 15397
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Solved Re: Problem with JS code

Post by skouliki September 14th 2019, 8:58 am

Problem solved & topic archived.
Please read our forum rules: ESF General Rules
skouliki
skouliki
Manager
Manager

Female Posts : 15397
Reputation : 1709
Language : English,Greek
Location : Greece

http://iconskouliki.forumgreek.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum