Post Reply 
[req] Toggle scripts
Feb. 26, 2009, 08:52 PM
Post: #1
[req] Toggle scripts
Hi all, i wrote a filter to convert all the javascripts from ad sources to a link. But i'm trying to toggle them when clicking in these links but i don't know if it is possible .

This is a modified version to work without the ad-sources list, the test page will be any page from geocities, for example the page from sidki

How it works:
1) In \3 is stored the url of the javascript
2) <script*</script> is stored in \8
3) <script*</script> will be replaced for a dynamic link
4) When we click in the dynamic link, it will rewrite itself to load the script and use it. To download the script i use <img src=\3>, and later \8 to use it. But i'm not sure if this will really work, any ideas?

Note: I don't know anything about javascript. I think some scripts must be loaded with the page and executed with the body onload. But other scripts not executed in the beginning could work using this filter or something similar?

Code:
[Patterns]
Name = "[TEST]<script> Block ad-SRC scripts {ln}090226 WIP forum version"
Active = TRUE
URL = "(^$KEYCHK(^S))$TYPE(htm) (^$LST(Bypass-Ads))"
Bounds = "$NEST(<script\s,</script >)"
Limit = 800
Match = "(((<script\s[^>]++src=$AV(\3)[^>]++>)&*(type="text/javascript"|language="javascript"))*</script >)\8"
        ""
        ""
        "$SET(5=prox)"
        ""
        "(^$TST(\3=*(.|/)$LST(Protect-LinksTo)*))"
        "$TST(\3=(http://(www|us).geocities.com/js_source*.js))$SET(4=Ad-Src)"
Replace = "</noscript><span><a class=\5 style="color: crimson ! important;" href="\3" title="\4: \9" onclick="this.parentNode.innerHTML=unescape('$ESC(<img width=0 src="\3">\8)');return false">"
          "TEST-[Script"
          "</a><a class=\5 style="color: green ! important;" href="http://addtolist//proxomitron//\3~reload~\u" target="_top" title="Add to Protect-LinksTo list">"
          "\4]"
          "</a></span>\r\n"
Add Thank You Quote this message in a reply
Feb. 26, 2009, 10:13 PM
Post: #2
RE: [req] Toggle scripts
(Feb. 26, 2009 08:52 PM)lnminente Wrote:  Note: I don't know anything about javascript. I think some scripts must be loaded with the page and executed with the body onload. But other scripts not executed in the beginning could work using this filter or something similar?

I agree. As a rule of thumb, scripts in the <head> block can't be hot-swapped, but those in the <body> block can.

At least that's what i seem to remember when playing with it, after ProxRocks asked for it, at CC a few years back. The method i'd use would be similar to "<iframe>: Toggle Third Party iFrames". That is, moving the src value to a dummy attribute, and replacing the real src value with a dummy URL. As to the dummy attribute, for iframes "longdesc" is working well, for scripts i would suggest "for".

Then, clicking the toggle would invoke a function that swaps "for" with "src". I don't think writing that function would require deep JS knowledge, which i don't have either. Maybe you could just copy over the respective function from proxjs-full.js. The function is called "inToggleC", and you'd need to replace "t.longDesc" with "t.htmlFor || t.getAttribute("for")".
Add Thank You Quote this message in a reply
Feb. 26, 2009, 10:42 PM
Post: #3
RE: [req] Toggle scripts
Thanks for the fast and helpful response Sidki. I will take a look to that function and see the differences. Maybe the filter is working as it is, i'm not sure because it's difficult to test. It works with the same method i use for toggling iframes too, also banners, divs, tables and td tags

Looking for a site wich load scripts inside the body to test this...
Add Thank You Quote this message in a reply
Feb. 26, 2009, 10:58 PM
Post: #4
RE: [req] Toggle scripts
Sure thing, lnminente, but darn, i've forgotten one thing!
That is using "document.write" on a page that has already loaded. While IE is more forgiving, Firefox and Opera tend to hang.
Add Thank You Quote this message in a reply
Mar. 02, 2009, 03:48 PM
Post: #5
RE: [req] Toggle scripts
sidki;

While you're correct about "document.write" not being able to execute correctly after the page has loaded, you can overcome that shortcoming by appending a forced refresh/reload. We used to use simply "document.location.reload(true)", but that now fails in some browsers. The fix seems to be too simple: "window.location.href = window.location.href".

There are the usual derivatives of course, such as frames, forms, even ordinary images.... anything that can be assigned a URL is subject to being refreshed. Put the appropriate DOM item in your statement, call it at the end of your function, and you should be good to go. Smile!

HTH


Oddysey

I'm no longer in the rat race - the rats won't have me!
Add Thank You Quote this message in a reply
Mar. 02, 2009, 05:44 PM
Post: #6
RE: [req] Toggle scripts
It's not my project, so lnminente may perceive that differently. Usually the idea of "toggle filters" is to change layout by manipulating the DOM (of the loaded document). If you reload the page, no matter if via script or manually, such changes are lost.

However, there are a couple of approaches available that replace the native write method with corresponding methods like createElement. Latter methods do work. I'll attach a script (written by others) that i was using for another project.


Attached File(s)
.js  doc.write.js (Size: 1.51 KB / Downloads: 719)
Add Thank You Quote this message in a reply
Mar. 03, 2009, 05:37 AM
Post: #7
RE: [req] Toggle scripts
(Mar. 02, 2009 05:44 PM)sidki3003 Wrote:  It's not my project, so lnminente may perceive that differently.
My point is only finding the easiest way to "turn on" a disabled script. Feel free to post whatever you want of course Sidki Wink

Note: My development of this is almost stopped as i'm not good with javascript... Sad
Add Thank You Quote this message in a reply
Mar. 04, 2009, 05:40 PM
Post: #8
RE: [req] Toggle scripts
sidki;
(Mar. 02, 2009 05:44 PM)sidki3003 Wrote:  It's not my project, so lnminente may perceive that differently.
True, that. However, you were the one who made the initial statement about reloading, so I responded directly. The way I figure it, everyone benefits, but I gave you my normal courtesy of directly addressing the first person to bring up a given instance. That's all, I swear! Wink

Quote:Usually the idea of "toggle filters" is to change layout by manipulating the DOM (of the loaded document). If you reload the page, no matter if via script or manually, such changes are lost.
Urmmm, I think we have a difference of opinion here. To me, toggling a filter to make its effect appear or disappear would sort of require that the page be re-rendered by the browser, no? (Or at least some portion of the page, perhaps such as an iframe.) And the idea of a toggle is that it be forced to assume a new state, be that the default state or otherwise. This new state really should be "saved" across page refreshes, or so I would think - else it would never be a toggle! The manner of doing so is best left up to the filter's author of course, I don't think there's any one 'best' way to do that.

createElement also requires a page refresh in order for the browser to render it. And while I'm at it, for those not at sidki's level of understanding, all this page refreshing is required because the browser has to calculate where to render each item (DOM element) on the screen. It can't simply leave in place everything already on the screen, untouched. That would definitely make for a messy rendition! Sad


While I'm certain that I've properly explained the basics of what happens for the mainstream browser (not to mention a small torrent of wannabe's), by no means have I given any shrift to the avant-garde stuff. It is entirely possible that one or more out-of-the-way browsers may have a method of rendering parts of the screen without touching the remaining items, but such has not come to my notice. But just to cover my butt, I'll quote A.C. Clarke: "When a noted scientist says that something might be possible, he is almost certainly right. When he says that something is absolutely impossible, he almost certainly wrong."

HTH


Oddysey

I'm no longer in the rat race - the rats won't have me!
Add Thank You Quote this message in a reply
Mar. 12, 2009, 03:30 PM
Post: #9
RE: [req] Toggle scripts
I confirm here my first filter was not working well. This attempt is working better, using Data_URI_scheme and still testing

Code:
[Patterns]
Name = "<script files> Block by adlist {ln}090312 TEST Forum version"
Active = TRUE
URL = "(^$KEYCHK(^S))$TYPE(htm) (^$LST(Bypass-Ads))"
Bounds = "$NEST(<script\s,</script >)"
Limit = 800
Match = "(((<script\s[^>]++src=$AV(\3)[^>]++>)&*(type="text/javascript"|language="javascript"))*</script >)\8"
        ""
        ""
        "$SET(5=prox)"
        ""
        "(^$TST(\3=*(.|/)$LST(Protect-LinksTo)*))"
        "$TST(\3=(http://(www|us).geocities.com/js_source*.js))$SET(4=Ad-Src)"
Replace = "</noscript><span><a class=\5 style="color: crimson ! important;" href="\3" title="\4: \9" onclick="this.parentNode.innerHTML=unescape('$ESC("
          "<iframe height="0" width="0" src="data:text/html;charset=utf-8,$ESC(\8)" </iframe>"
          ")');return false">"
          "[Script"
          "</a><a class=\5 style="color: green ! important;" href="http://addtolist//proxomitron//\3~reload~\u" target="_top" title="Add to Protect-LinksTo list">"
          "\4]"
          "</a>"
          "<img width=0 src="\3">"
          "</span>\r\n"
Add Thank You Quote this message in a reply
Apr. 01, 2009, 12:52 PM
Post: #10
RE: [req] Toggle scripts
I don't know js too but I just came cross this site and think the way it used to dynamically load script might work for you:
Code:
<a href="javascript:document.getElementsByTagName('head')[0].appendChild(document.createElement('script')).setAttribute('src','http://www.karmatics.com/aardvark/loader.js')" title="in-page demo of aardvark">run the demo</a>

I had added it to my bookmarklet collection. How about integrating it into the prox menu? Smile!
Add Thank You Quote this message in a reply
Apr. 01, 2009, 01:42 PM (This post was last modified: Apr. 01, 2009 02:02 PM by sidki3003.)
Post: #11
RE: [req] Toggle scripts
(Apr. 01, 2009 12:52 PM)whenever Wrote:  How about integrating it into the prox menu? Smile!

As for a script toggle, as mentioned above, i've tried but didn't get it to work reliably. No Expression

edit: whenever, i've loaded that loader.js. It looks nice, but you'd need to load a bunch of remote scripts for it. Besides, "Toggle DOM Path" already shows that info. In a not so fancy way, however.
Add Thank You Quote this message in a reply
Apr. 01, 2009, 03:00 PM
Post: #12
RE: [req] Toggle scripts
(Apr. 01, 2009 01:42 PM)sidki3003 Wrote:  Besides, "Toggle DOM Path" already shows that info. In a not so fancy way, however.
How about an upgrade? Smile!

The author kindly allow redistribution of his work:
http://karmatics.com/aardvark/loader.js Wrote:// This file is in the public domain.
// You may copy this file, alter it as you wish, and serve your modification
// from your site.

I just made a copy of all the remote scripts referred by the loader.js locally and use $RDIR to redirect the request to the local copy. It's also easy to modify the loader.js to use http://local.ptron to serve the scripts.
Add Thank You Quote this message in a reply
Apr. 01, 2009, 03:28 PM
Post: #13
RE: [req] Toggle scripts
(Apr. 01, 2009 03:00 PM)whenever Wrote:  How about an upgrade? Smile!

Fine by me. If someone can condense these scripts (~53KB) into a reasonable number of functions, each with reasonable size, integrate a toggle (undo), and merge it into proxjs-x-menu.js.
Add Thank You Quote this message in a reply
Apr. 01, 2009, 04:03 PM
Post: #14
RE: [req] Toggle scripts
Is it possible to make proxjs-x-menu.js read a config file to load user defined menu items? That way users could put the js files under the html directory and then use prox menu to launch their favorite bookmarklets, under all browsers.

btw, my opera is set to disable javascript globally. Sometimes when I want the prox menu, I have to enable javascript and reload the page. I am considering using this technique to load the proxjs-x-menu.js dynamically without a page reloading. Is it feasible? Does prox menu rely on proxjs-full.js?
Add Thank You Quote this message in a reply
Apr. 01, 2009, 04:35 PM
Post: #15
RE: [req] Toggle scripts
(Apr. 01, 2009 04:03 PM)whenever Wrote:  Is it possible to make proxjs-x-menu.js read a config file to load user defined menu items? That way users could put the js files under the html directory and then use prox menu to launch their favorite bookmarklets, under all browsers.

I think it's possible to have the menu script look for a user file, and, if present, load its data via XMLHttpRequest. A couple of people have already asked for such a feature. However, it would probably require quite some skill and time.


Quote:btw, my opera is set to disable javascript globally. Sometimes when I want the prox menu, I have to enable javascript and reload the page. I am considering using this technique to load the proxjs-x-menu.js dynamically without a page reloading. Is it feasible? Does prox menu rely on proxjs-full.js?

proxjs-x-menu.js is never preloaded, always loaded dynamically on first page click. It's basically a data file. You do need proxjs-full.js (or another, little script) to do the XHR stuff and positioning.
Add Thank You Quote this message in a reply
Post Reply 


Forum Jump: