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.
The forum of the forums
2 posters

    What should I add to this code assignments change the caption of the photo.

    smurfavr
    smurfavr
    Active Poster


    Male Posts : 1881
    Reputation : 22
    Language : Bulgarian

    Solved What should I add to this code assignments change the caption of the photo.

    Post by smurfavr 7/9/2014, 23:35

    What should I add to this code assignments change the caption of the photo. 

    What should I add to this code assignments change the caption of the photo.  7459021l

    Code:
    $(function() {
        var replace1 = 'Трябва да си регистриран за да виждаш линковете..';
        var replace2 = 'Вие нямате права за сваляне !';
        var replace3 = '$1Свален $2 пъти.';
     
        var post = $('.postbody div');
        var atbox = $('.attachbox');
        var reg1 = /\[You must be.*?to see this [A-Z]+.\]/ig;
        var reg2 = /You don't have permission to download attachments./ig;
        var reg3 = /(\(\d+ [A-Z]+\)) Downloaded (\d+) times/ig;
       
        for (i=0;i<post.length;i++)if(reg1.test(post[i].innerHTML))post[i].innerHTML=post[i].innerHTML.replace(reg1,replace1);
        for (i=0;i<atbox.length;i++)if(reg2.test(atbox[i].innerHTML) || reg3.test(atbox[i].innerHTML))atbox[i].innerHTML=atbox[i].innerHTML.replace(reg2,replace2).replace(reg3,replace3);
    });
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: What should I add to this code assignments change the caption of the photo.

    Post by Ange Tuteur 7/10/2014, 00:14

    Hello smurfavr,

    I simplified the code for you, replace your script by :
    Code:
    $(function() {
      replaceText('.postbody div', /\[You must be.*?to see this [A-Z]+.\]/ig, 'Трябва да си регистриран за да виждаш линковете..');
      replaceText('.attachbox', /You don't have permission to download attachments./ig, 'Вие нямате права за сваляне !');
      replaceText('.attachbox', /(\(\d+ [A-Z]+\)) Downloaded (\d+) times/ig, '$1 Свален $2 пъти.');
      replaceText('.attachbox', /Attachments/g, 'Attachments text');
        
      function replaceText(element, reg, rep){var el=$('.post '+element);for(i=0;i<el.length;i++)if(reg.test(el[i].innerHTML))el[i].innerHTML=el[i].innerHTML.replace(reg,rep)}
    });

    In the script you'll see :
    Code:
    replaceText('.attachbox', /Attachments/g, 'Attachments text');

    Replace Attachments text by the texts you want to display.


    Explanation :

    To replace texts simply write replaceText();, between the parenthesis you'll fill out the following information in order :
    Element : The element the texts are inside
    Reg : The regular expression to search for the texts
    Rep : The replacement for the searched texts

    When done your result should be :
    Code:
    replaceText('.attachbox', /Attachments/g, 'Attachments text');
    smurfavr
    smurfavr
    Active Poster


    Male Posts : 1881
    Reputation : 22
    Language : Bulgarian

    Solved Re: What should I add to this code assignments change the caption of the photo.

    Post by smurfavr 7/10/2014, 00:25

    Thank you Ange Tuteur.Everything works.
    Ange Tuteur
    Ange Tuteur
    Forumaster


    Male Posts : 13207
    Reputation : 3000
    Language : English & 日本語
    Location : Pennsylvania

    Solved Re: What should I add to this code assignments change the caption of the photo.

    Post by Ange Tuteur 7/10/2014, 00:28

    You're welcome :rose:

    Topic archived

    Have a good day ! ^^

      Current date/time is 9/23/2024, 14:28