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.

failed to make Script

3 posters

Go down

Solved failed to make Script

Post by Michael_vx Fri 23 Oct 2015 - 4:21

hello i have find that Script somewhere on the internet for forumotion to replace any image link by
Code:
[img]the image link[/img]
but its not working i tried to fix it but still not working the Script i find
Code:
$(function() {
            var links = $('.postbody a', document.getElementById('main-content')), reg = /\.(?:png|jpeg|jpg|gif)$/i;
            for(var i = 0, link; (link = links[i++]); ) {
                if(reg.test(link.href)) {
                    link.innerHTML = '[img]%27%20+%20link.href%20+%20%27[/img]';
                }
            }
        });
the problem i face is the Script replace the image link by
Code:
[img]%27%20+%20link.href%20+%20%27[/img]
the changes i tried is replace the text
%27%20+%20link.href%20+%20%27
i tried
link.href
but failed i tried *.* failed too so is there a way to fix it
im also thinking about making a Script to replace youtube links to show the vedio insted of vedio link like the image replacer
Michael_vx
Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: failed to make Script

Post by SLGray Fri 23 Oct 2015 - 4:39

Are you talking about when you are posting images and videos?  If yes, then you can use the WYSIWYG mode in the editor.


failed to make Script Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51576
Reputation : 3525
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: failed to make Script

Post by Michael_vx Fri 23 Oct 2015 - 9:33

may be something was missed
after post sent
what i meant by image is when i post dierct image link
like this https://i.servimg.com/u/f21/16/89/96/68/slgray10.png
it should be replaced with the Script to be
Code:
[img]http://i21.servimg.com/u/f21/16/89/96/68/slgray10.png[/img]
but its replace even the the link itself
Michael_vx
Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: failed to make Script

Post by Michael_vx Sat 24 Oct 2015 - 9:39

bump
any way to solve the main problem ?
Code:
$(function() {
            var links = $('.postbody a', document.getElementById('main-content')), reg = /\.(?:png|jpeg|jpg|gif)$/i;
            for(var i = 0, link; (link = links[i++]); ) {
                if(reg.test(link.href)) {
                    link.innerHTML = '[img]%27%20+%20link.href%20+%20%27[/img]';
                }
            }
        });
Michael_vx
Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: failed to make Script

Post by Ange Tuteur Sat 24 Oct 2015 - 11:06

Hi @Michael_vx,

The reference to link.href is in string notation, so the string is only going to print "link.href" and not the href value of link. You need to concat link between the two strings like this :
Code:
$(function() {
  var links = $('.postbody a', document.getElementById('main-content')), reg = /\.(?:png|jpeg|jpg|gif)$/i;
  for(var i = 0, link; (link = links[i++]); ) {
    if(reg.test(link.href)) {
      link.innerHTML = '[img]' + link.href + '[/img]';
    }
  }
});
Ange Tuteur
Ange Tuteur
Forumaster

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

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: failed to make Script

Post by Michael_vx Sat 24 Oct 2015 - 20:31

thats a good news thanks for that info i think i have a lot to learn
now the link appear as same link i post but the image wont show
http://miclap.logu2.com/t2-topic
i still not sure what he reson
Michael_vx
Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: failed to make Script

Post by Ange Tuteur Sat 24 Oct 2015 - 21:10

Oh right, silly me.. I should've noticed you were using bbcode tags. failed to make Script 1f633 You need to use the HTML image tag instead, as bbcode is only parsed server-side.
Code:
$(function() {
  var links = $('.postbody a', document.getElementById('main-content')), reg = /\.(?:png|jpeg|jpg|gif)$/i;
  for(var i = 0, link; (link = links[i++]); ) {
    if(reg.test(link.href)) {
      link.innerHTML = '<img src="' + link.href + '"/>';
    }
  }
});
Ange Tuteur
Ange Tuteur
Forumaster

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

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: failed to make Script

Post by Michael_vx Sat 24 Oct 2015 - 21:33

failed to make Script 1f60a 
i think im the silly one
i stuck in a little small thing i scrow up everything
i dont know how to thank you for this big help
you are the life savior
this topic is now solved
only when you close the the topic wish me luck of my next Script that should do the same thing with youtube
thanks again for giving me the hand in solving this
Michael_vx
Michael_vx
Forumember

Male Posts : 659
Reputation : 29
Language : Arabic and some English
Location : Egypt

Back to top Go down

Solved Re: failed to make Script

Post by Ange Tuteur Sat 24 Oct 2015 - 21:41

No problem. ^^

Topic archived

Have a good weekend.

If you need any additional references these are some good sources for learning :
https://developer.mozilla.org/en-US/docs/Web/JavaScript
http://www.quackit.com/
http://www.w3schools.com/
Ange Tuteur
Ange Tuteur
Forumaster

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

https://fmdesign.forumotion.com

Back to top Go down

Back to top

- Similar topics

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