473,785 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Greasemonkey: Trying to replace LJ's YouTube placeholders with a link.

XtinaS
3 New Member
I'm trying to write a script for Greasemonkey that will, in LiveJournal, replace a placeholdered embedded YouTube thing with a link to the video. In LiveJournal, you can set an option to have a placeholder instead of the actual embedded YouTube video. This is what that code looks like:

Expand|Select|Wrap|Line Numbers
  1. <div class="LJ_Placeholder_Container" style="width: 475px; height: 405px;">
  2.     <div class="LJ_Placeholder_HTML" style="display: none;">%3C%69%66%72%61%6D%65%20%73%72%63%3D%22%68%74%74%70%3A%2F%2F%6C%6A%2D%74%6F%79%73%2E%63%6F%6D%2F%3F%6A%6F%75%72%6E%61%6C%69%64%3D%31%32%37%37%36%36%26%6D%6F%64%75%6C%65%69%64%3D%34%26%61%75%74%68%5F%74%6F%6B%65%6E%3D%73%65%73%73%69%6F%6E%6C%65%73%73%3A%31%31%39%38%36%39%39%32%30%30%3A%65%6D%62%65%64%63%6F%6E%74%65%6E%74%3A%31%32%37%37%36%36%25%32%36%34%3A%65%30%30%65%62%30%33%63%32%32%32%33%31%65%30%30%64%65%61%39%33%39%32%37%65%61%37%62%65%62%36%35%35%31%33%33%30%38%38%39%22%20%77%69%64%74%68%3D%22%34%37%35%22%20%68%65%69%67%68%74%3D%22%34%30%35%22%20%61%6C%6C%6F%77%74%72%61%6E%73%70%61%72%65%6E%63%79%3D%22%74%72%75%65%22%20%66%72%61%6D%65%62%6F%72%64%65%72%3D%22%30%22%20%63%6C%61%73%73%3D%22%6C%6A%5F%65%6D%62%65%64%63%6F%6E%74%65%6E%74%22%20%6E%61%6D%65%3D%22%65%6D%62%65%64%5F%31%32%37%37%36%36%5F%34%22%3E%3C%2F%69%66%72%61%6D%65%3E</div>
  3.     <div class="LJ_Container"></div>
  4.     <a href="" onclick="return false;">
  5.         <img src="http://stat.livejournal.com/img/videoplaceholder.png" class="LJ_Placeholder" title="Click to show embedded content" />
  6.     </a>
  7. </div>
  8.  
That pile of hex turns into this iframe element:

Expand|Select|Wrap|Line Numbers
  1. <iframe src="http://lj-toys.com/?journalid=711176&moduleid=8&auth_token=sessionless:1198684800:embedcontent:711176%268:6d73c68d2e1e81bc3055dafe2c66a79ebd101129" width="475" height="405" allowtransparency="true" frameborder="0" class="lj_embedcontent" name="embed_711176_8"></iframe>
  2.  
(I don't know why it points to lj-toys.com. That's some LJ thing I don't know.)

I want to replace that code block (node?) with just the link. I can do it in normal Javascript, if I hard-code the string:

Expand|Select|Wrap|Line Numbers
  1. var afts, befs, news;
  2.  
  3. befs = "<div class='LJ_Placeholder_HTML' style='display: none;'>%3C%69%66%72%61%6D%65%20%73%72%63%3D%22%68%74%74%70%3A%2F%2F%6C%6A%2D%74%6F%79%73%2E%63%6F%6D%2F%3F%6A%6F%75%72%6E%61%6C%69%64%3D%31%32%37%37%36%36%26%6D%6F%64%75%6C%65%69%64%3D%33%26%61%75%74%68%5F%74%6F%6B%65%6E%3D%73%65%73%73%69%6F%6E%6C%65%73%73%3A%31%31%39%38%36%39%39%32%30%30%3A%65%6D%62%65%64%63%6F%6E%74%65%6E%74%3A%31%32%37%37%36%36%25%32%36%33%3A%37%63%63%62%63%64%64%30%30%63%38%31%66%61%35%32%66%61%66%63%66%33%65%36%38%37%65%63%36%34%64%64%65%34%66%36%39%39%37%31%22%20%77%69%64%74%68%3D%22%34%37%35%22%20%68%65%69%67%68%74%3D%22%34%30%35%22%20%61%6C%6C%6F%77%74%72%61%6E%73%70%61%72%65%6E%63%79%3D%22%74%72%75%65%22%20%66%72%61%6D%65%62%6F%72%64%65%72%3D%22%30%22%20%63%6C%61%73%73%3D%22%6C%6A%5F%65%6D%62%65%64%63%6F%6E%74%65%6E%74%22%20%6E%61%6D%65%3D%22%65%6D%62%65%64%5F%31%32%37%37%36%36%5F%33%22%3E%3C%2F%69%66%72%61%6D%65%3E</div>";
  4.  
  5. afts = new RegExp(".*%3C%69%66%72%61%6D%65%20%73%72%63(.*)%22%20%77%69%64%74%68.*div>", "g");
  6.  
  7. news = unescape('%3C%61%20%68%72%65%66' + befs.replace(afts, "$1") + '%22%3E%59%6F%75%54%75%62%65%20%4C%69%6E%6B%3C%2F%61%3E');
  8.  
  9. document.write(news);
  10.  
Apologies for the long hex chunks. And yeah, my regex is perhaps messed up; input on how to make that cleaner would be nice, but isn't necessary.

What that does is replace "iframe src" with "a href", and cuts out everything from "width" to the end. It then adds ">YouTube Link</a>" to the end.

I don't know how to get this working in Greasemonkey, though. I can get it started, thanks to the Dive Into book:

Expand|Select|Wrap|Line Numbers
  1. var allDivs, thisDiv;
  2.  
  3. allDivs = document.evaluate("//div[@class='LJ_Placeholder_Container']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  4.  
  5. for (var i = 0; i < allDivs.snapshotLength; i++) {
  6.   thisDiv = allDivs.snapshotItem(i);
  7.   //Within this node, find the line that has the hex.
  8.   //Put that line into a variable?
  9.   //Run the replacements, as listed above.
  10.   //Insert the new line before the node.
  11.   //Remove the node:
  12.   thisDiv.parentNode.removeChild(thisDiv);
  13. }
  14.  
Would it make sense to use regex to find the multiple lines, capture the portion of the hex that I want, and replace it with the unescaped new hex? That might remove the need to remove the node...

How would I do this?
Dec 26 '07 #1
3 3663
acoder
16,027 Recognized Expert Moderator MVP
Either use innerHTML to get the content or the DOM methods (example).
Dec 27 '07 #2
XtinaS
3 New Member
acoder:

I cannot thank you enough. That pointed me to exactly where I was trying to go. Oh my goodness.

Thanks!!
Dec 28 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
You're welcome. Glad it helped. Post again if you have any more questions.
Dec 28 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2629
by: kn0ckturnal | last post by:
when i try to view video on youtube or other type video, it wont load and it saids: (from youtube) Hello, you either have JavaScript turned off or an old version of Macromedia's Flash Player. Click here to get the latest flash player. (other site) You need to upgrade your Flash Player This is replaced by the Flash content. Place your alternate content here and users without the Flash plugin or with Javascript turned off will see this....
5
2137
by: kevin | last post by:
If you go here http://www.youtube.com/ how do they put the plus button over the image? Also is it possible to include more the one button. Thanks... ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
1
1592
by: MKR | last post by:
I need some help writing a Greasmonkey user script. An application that I use generates HTML pages with tags like this: <input type="button" name="9999" value="1234567890" onClick="showitem('1234567890'); return false"> Sometimes I just want to copy the item number (i.e. the "value" attribute), other times I actually want to click the button and see the item. Right now I can see the item number as a button label, but I cannot copy its...
2
2690
by: 9icj4u613jeqrx8 | last post by:
Hi, I need some help with IE browser programming (in .NET). I'm trying to add a button to the IE toolbar, and on the click of the button open a popup window with a remote URL. Secondly, I'm trying to highlight certain predefined words on particular web sites through the IE plugin itself. To add an IE button, I've found this neat article:
1
1924
by: nmccart | last post by:
Greetings. I have recently discovered the Grease Monkey add-in for FireFox. It has a lot of potential, and I am really enjoying using it to simplify and automate some repetitive tasks I perform on a regular (several times a day) basis. Here is what I cannot figure out: One site I visit (PHP) generates a list of links based on certain conditions (time of day, luck of the draw, who knows?). I want to click a SPECIFIC link if it exists. If...
6
1386
by: Rauan Maemirov | last post by:
Hi, all. I'm trying to replace <object ...><embed... /></objectwith <imgtag and vice-verse. It's like implementation of media plugin of Tiny MCE editor. I tried to watch their code, but it's too complicated and has a lot of unnecessary code. And the main reason is i'm weak in javascript rewriting. :) I need just simple rewrite for e.g. this <object width="425" height="355"><param name="movie" value="URL"></ param><param name="wmode"...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.