|
How to test a variable against another variable?
|
|
Aug. 21, 2008, 04:04 AM
Post: #1
|
|||
|
|||
|
How to test a variable against another variable?
I am trying to write a filter which will add links to Google cache results to allow continuing using the cache, just like this userscript does.
I intend to add links only for those urls which are from the same host, so I use below code to extract the host address and sotre it in a global variable for later use. Code: (This is Google's cache of <a[^>]+>http://\1/*</a>)\0$SET(currentHost=\1)The next step is to match only the urls from the same host. I tried below code but it seems the $GET command can't be expanded in match field just like the help file stated: Code: <a*href=$AV($GET(currentHost)/\2)*</a>Then I tried to capture the host part into a variable: Code: <a*href=$AV(\7/\2)*</a>and tested it with the currentHost variable in the replace field but it doesn't work either. Code: $TST(\7=$GET(currentHost))$SET(......)Any ideas? |
|||
|
Aug. 21, 2008, 04:14 AM
Post: #2
|
|||
|
|||
|
RE: How to test a variable against another variable?
I find variables confusing sometimes; try reading Sidki's "Techniques" file, I think some of it might apply to what you're trying to accomplish: http://sidki.proxfilter.net/prox/sidki-e...niques.txt
|
|||
|
Aug. 21, 2008, 05:28 AM
Post: #3
|
|||
|
|||
|
RE: How to test a variable against another variable?
I read that already and even searched sidki's config set but couldn't find an example on testing variable against variable.
![]() Is there any other way to do what I want to do? |
|||
|
Aug. 21, 2008, 03:03 PM
Post: #4
|
|||
|
|||
RE: How to test a variable against another variable?
(Aug. 21, 2008 04:04 AM)whenever Wrote: The next step is to match only the urls from the same host. I tried below code but it seems the $GET command can't be expanded in match field just like the help file stated:Finally worked out a way by using a memory block list for the hostname match. The below filter is just for demonstrating the technique and may not ready for real use. Code: [Patterns] |
|||
|
Oct. 08, 2008, 09:56 PM
Post: #5
|
|||
|
|||
RE: How to test a variable against another variable?
whenever Wrote:The next step is to match only the urls from the same host. I tried below code but it seems the $GET command can't be expanded in match field just like the help file stated: Here's a test filter that does what you want, I think. Code: [Patterns]In the log window, these will match: Code: <a href="http://www.foobar.com/foo_for_all/" >foo for all </a>This one does not: Code: <a href="http://www.nofoo.com/foo_for_all/" >foo for all </a>HTH z12 |
|||
|
Oct. 10, 2008, 03:28 AM
Post: #6
|
|||
|
|||
|
RE: How to test a variable against another variable?
Thank you z12. I found that trick was documented in the help file too, just inside the $TST() command section.
Each time I reread the help file, I learn something which was not noticed or understood before. So, here is an improved filter without using a memory block file. Code: [Patterns] |
|||
|
Oct. 10, 2008, 08:42 AM
Post: #7
|
|||
|
|||
RE: How to test a variable against another variable?
whenever Wrote:Each time I reread the help file, I learn something which was not noticed or understood before. Same with me. It's definitely not a file you read just once. As Kye-U mentioned, sidki's Techniques.txt is also quite helpful. Especially in regards to variables. BTW, as per your thread title, this tests if two variables, to & tc, are equal: Code: $TST(to=$TST(tc))While this may seem obvious to some, it took me a while to figure it out. z12 |
|||
|
Oct. 10, 2008, 09:04 AM
Post: #8
|
|||
|
|||
|
RE: How to test a variable against another variable?
Great! Now it seems obvious with knowing the above trick.
I learned another trick about $TST() at Castlecops, maybe you are interested in it too. |
|||
|
Oct. 10, 2008, 12:30 PM
Post: #9
|
|||
|
|||
|
RE: How to test a variable against another variable?
If you use "This is Google's cache of", this will only work for english people. In my case, being spanish, i see "Esta es la versión en caché de" so it will never match. Please let's tray doing global filters.
How? Taking "currentHost" from the actual url of the cache Code: $URL(*cache:*:(*)\5/*)$SET(currentHost=\5)Code: [Patterns]I like this filter, thanks for it ![]() Updated: Changed "/search?hl=en&q=cache" to "/search?q=cache" |
|||
|
Oct. 10, 2008, 01:18 PM
Post: #10
|
|||
|
|||
|
RE: How to test a variable against another variable?
That's better. I made some improvements based on your filter to cover the below situation:
cache:www.test.com&other= No http:// between, no ended "/" cache:www.test.com currentHost is the last parameter Code: [Patterns] |
|||
|
Oct. 10, 2008, 06:30 PM
Post: #11
|
|||
|
|||
|
RE: How to test a variable against another variable?
Better again. Thanks!
|
|||
|
Oct. 11, 2008, 05:55 AM
Post: #12
|
|||
|
|||
|
RE: How to test a variable against another variable?
Since host extraction is excuted each time, there is no need to use a global var any longer. The below new version also improved the host extraction and took care of the :// encoding.
Code: [Patterns] |
|||
|
Oct. 11, 2008, 10:13 AM
Post: #13
|
|||
|
|||
RE: How to test a variable against another variable?
whenever Wrote:I learned another trick about $TST() at Castlecops, maybe you are interested in it too. At first glance, the castlecops $TST looks a bit odd. Basically it's just this: Code: $TST(VariableName=Matching expression)Both the * and \1 match the current value of the VariableName. The \1 has the added bonus of saving that value. You can do this wherever you can use $TST(). BTW, personally, I would put the \s back into your filters Bounds expression. Code: Bounds = "<a\s*</a>"Perhaps you should post your filter in Website Customization when your done with it. More people will probably see it there. ![]() z12 |
|||
|
Oct. 11, 2008, 12:21 PM
Post: #14
|
|||
|
|||
|
RE: How to test a variable against another variable?
You are right on the \s. The fixed version is posted here.
|
|||
|
Oct. 11, 2008, 01:52 PM
Post: #15
|
|||
|
|||
|
RE: How to test a variable against another variable?
Agree!!
I used sometimes a\s but sometimes i removed it to test for area, but i still haven't tested it by now. I will play with (a|area)\s More ideas are welcome;) Edited: Deleted what i said about $NEST or $INEST, it's usefull for tables, but not here. It's also confusing sometimes, so i removed it from here for that reason. |
|||
|
« Next Oldest | Next Newest »
|

Search
Member List
Calendar
Help





![[-]](images/ONi/collapse.gif)



