Extensions :  K-Meleon Forum
All about K-Meleon extensions. 
I need a redirect extension. I can't find one. Please help me.
Posted by: Jennifer
Date: January 08, 2016 12:41AM

OK, I am using K-Meleon 1.8.24 and I need a redirect extension for it. It should be able to use regex to do redirections. For example, it should redirect addresses of the form:

http://imgur.com/XXXXXX

to addresses of the form:

http://i.imgur.com/XXXXXX.jpg

and other redirections that I can define.

Please help me.

Options: ReplyQuote
Re: I need a redirect extension. I can't find one. Please help me.
Posted by: rodocop
Date: January 08, 2016 05:20AM

Need this too!


Latest Release KM75.1 Latest dev KM76RC ||| Visit The K-Meleon Place and join me there!
Old good stuff: KM-1.6db+NS © dugbugoffice // KM-16-S2014 © Fred // KM-1.6beta2.6 © JamesD // KM Twin+ © rodocop // KM 1.8.24.22 © adodupan

RECOMMENDED! K-Meleon 76 Pro ==» Download portable: 7zip or EXE =//= Discuss on forum
K-Meleon 75.1 Pro: Download =//= Discuss || Portable Flash plugin (x86/x64 DLLs)

Options: ReplyQuote
Re: I need a redirect extension. I can't find one. Please help me.
Posted by: siria
Date: January 08, 2016 08:30AM

Siigh.. Would love to, and already have an old personal macro for much the same purpose (except regex, but not absolutely necessary) - but too busy still with other stuff and other unfinished macros sad smiley
Knowing JamesD, he's perhaps almost finished again with a new one... cool smiley
Anyway, in case it takes same time - would recommand to login and follow this thread to get email notices.

And I read this like you guys are willing and able to code your own special replacements, by editing the kmm directly, just based on some syntax examples cool smiley And of course can ask for help in the forum anytime, just not get a comfortable GUI.

-----------------------
example:
http://imgur.com/XXXXXX => http://i.imgur.com/XXXXXX.jpg

myredirects_method1{
$_site=hostname($URL);
#
if ($_site=="imgur.com") {
$_url=sub("http://imgur","http://i.imgur",$URL)."jpg";
}
if ($_site=="blabla.com") {
$_url=sub...whatever...;
}
if ($_site=="zzzzz.com") {
$_url=sub...whatever...;
}
if (index($URL,".bbb.org/pics/")<20) {
$_url=sub.....whatever...;
$_url=substr($_url,index...)...whatever...;
}
open($_url);
# opentab($_url);
}

myredirects_method2{
if (index($URL,"http://imgur.com/")==0) {
# replace with your own strings here:
injectJS("var x; x=document.href; x=x.replace(/string1/g,'string2'); document.href=x ;");
}
...
}

-----------------------

and the next prob is on how to implement it.
It could either work "OnLoad", that means first the original page is loaded and when finished the redirected is loaded....
Or alternatively it could only be redirected when clicking a menu or button...
Or links could have the redirect option on the right-click menu...
Or could be called via mousegesture...

But what I can not do is a redirect of a link on left-click.
If need be, it could be put at middle-click for links...



Edited 5 time(s). Last edit at 01/08/2016 03:35PM by siria.

Options: ReplyQuote
Re: I need a redirect extension. I can't find one. Please help me.
Posted by: JamesD
Date: January 08, 2016 10:00AM

Quote
siria
Knowing JamesD, he's perhaps almost finished again with a new one.

I am still scratching my head and trying to figure out if there is a method or is every redirect unique. What is "regex"?

I, also, cannot find a way to do anything on a left click.

Options: ReplyQuote
Re: I need a redirect extension (regex, regexp, regular expressions)
Posted by: siria
Date: January 08, 2016 02:44PM

RegExp ("regular expressions") is some sort of highly sophisticated, often unavoidable and really handy matchcode-syntax, but just like javascript awfully complicated - will never get beyond most simple basics ;-)

http://www.codeguru.com/cpp/cpp/string/regex/article.php/c2791/Using-Regular-Expressions-for-SearchReplace.htm

Better editors like Notepad++ offer it as an option in Search/Replace functions. It can match, compare, delete or replace entire keys of any length and content, e.g. in the middle of a string, like www.example.com/read.php?id=...&page=...
Additionally it can be used to match only e.g. numbers, or replace only certain characters or certain words from a given range.

Very handy for e.g. CSS files because those cannot do any calculations by themselves:
https://developer.mozilla.org/en-US/docs/Web/CSS/@document
https://forum.userstyles.org/discussion/29682/help-with-moz-document-and-regexp

But the syntax... oh horror...
So far have only realized to match e.g. aaa*bbbb the syntax must be written aaaa.*?bbbb
And real dots must be escaped, because otherwise they mean "1 single character of any sort":
www\.example\.com/id=.*?&page=etc

If you master it, it sure is great, like javascript... cool smiley
Anyway, awhile ago have tried to find if there's some prepared way for macrolanguage, but no luck sad smiley
That means injectJS with a javascript must be used, something like (??)
var x; x=document.href; x=x.replace(/string1/g,'string2'); return x;

The other prob is for KM-versions where injectJS cannot return anything, like KM74, and considering KM1.8 is based on KM74, am not sure if it's fixed there already or not.

Frankly: as long as it's also possible to use macrolanguage for replacements with sub, substr, index, that code is easier to read for people macrowired like me, even if the code itself is longer and more complicated. Just... some basics would still be really handy sometimes!

Then again... if it's just about loading a new url, injectJS could handle that itself...
Will add that example in the macro snippet above, but not tested.



Edited 1 time(s). Last edit at 01/08/2016 03:28PM by siria.

Options: ReplyQuote
Re: I need a redirect extension (regex, regexp, regular expressions)
Posted by: JamesD
Date: January 08, 2016 08:03PM

Quote
siria
RegExp ("regular expressions") is some sort of highly sophisticated, often unavoidable and really handy matchcode-syntax, but just like javascript awfully complicated
.
.
But the syntax... oh horror...

Now, I remember. After my last use of Regular Expressions, I told my mind to never, ever consider them again. I agree with you about using the Macro Language.

OnLoad event will be of no help. If the URL is not right then often you reach a site 404 landing page and you no longer have the original URL.

We used to have the ability to 'read' the URL in a left click, but Mozilla dropped that ability for speed.

Hovering over a link with the mouse, lets the URL show in the statusbar. We could have a right-click, or some other user initiated action, run some code to 'adjust' the URL according to rules that are coded. That would require constant checking of the statusbar by the user. I do not have the patience or memory to do that, but perhaps Jennifer would.

If requested, I would be glad to to try to write such a macro.

Options: ReplyQuote
Re: I need a redirect extension (regex, regexp, regular expressions)
Posted by: JamesD
Date: January 08, 2016 10:09PM

I could not resist playing with this.

The attached code is a demo. Some lines need to be commented out and other lines need the comment removed for actual use.



Edited 1 time(s). Last edit at 01/08/2016 10:10PM by JamesD.

Attachments: MyRedirects.7z (982 bytes)  
Options: ReplyQuote
Re: I need a redirect extension (regex, regexp, regular expressions)
Posted by: siria
Date: January 09, 2016 02:50AM

Quote
JamesD
I could not resist playing with this.

LOL! Yes, I know that prob too well myself grinning smiley

@Jennifer
For playing with macros, an editor with syntax-highlighting helps enourmously to detect little syntax errors. Recommend this one, ancient but with special macro-modifications:
http://kmeleon.sourceforge.net/forum/read.php?9,109335,129077#msg-129077
And of course in general, Tools>Error Console helps enourmously too!
Had overlooked it for an eternity in the beginning, because in the toolbar that thing carries the name "javascript" console (!), that misunderstanding has cost me lots of unnecessary gray hairs sad smiley

Options: ReplyQuote


K-Meleon forum is powered by Phorum.