Extensions :  K-Meleon Web Browser Forum
All about K-Meleon extensions. 
Converting Userscript to Macro
Posted by: Zero3K
Date: March 29, 2015 05:03PM

Is it possible to do so?

Options: ReplyQuote
Re: Converting Userscript to Macro
Posted by: rodocop
Date: March 29, 2015 07:00PM

1) Use StyleScriptia extension by siria

2) inject JS into kmm using Firebug Lite macro as example

# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage)

# ----------km firebug lite----------------------------------------------------------


firebug{injectJS("var firebug=document.createElement('script');
firebug.setAttribute('src','http://getfirebug.com/releases/lite/1.4/firebug-lite-beta.js'winking smiley;
document.body.appendChild(firebug);(function(){if(window.firebug.version){firebug.init();
}else{setTimeout(arguments.callee);}})();void(firebug)");
}

firebug_BuildMenu{
setmenu("Development",inline,firebug_page,-1);
setmenu(firebug_page,macro,"Firebug Lite",firebug);
}

$OnInit=$OnInit."firebug_BuildMenu;";
# --------------------------------
$macroModules=$macroModules."firebug;";



Edited 4 time(s). Last edit at 03/29/2015 07:04PM by rodocop.

Options: ReplyQuote
Re: Converting Userscript to Macro
Posted by: siria
Date: March 29, 2015 07:21PM

There's no need to "convert" the script itself, if it only consists of a single JS-file, just "call" it by a macro.
The only prob is, how long is it? Don't know if there's still a size limit for "readfile" command in KM75. In older versions it used to be around 32kB, which was a huge prob and I made some complicated workarounds for it, but I have some dim memory Dorian mentioned that limit was removed in 75... Could remember wrong, but that sure would solve a lot of problems.

Anyway, you could test if that style works when calling it by macro StyleonMini (mini-version of StyleScriptia ;-)
If yes, you can just as well open a fix file with StyleonMini too, by adding the file path in brackets

EXAMPLE how to add it in the Help-MENU by editing your menus.cfg. Add this at bottom:

!&Help{
Style zero1=macros(StyleonMini_openLongFILE(C:\scripts\mystyle_zero1.js))
}

Or to add a button via toolbars.cfg, use the same macros command as above.

There are countless other ways too, shortcuts etc.

=======

Yes, inserting the code directly in the kmm like firebug is a nice way too, but mostly for very short scripts, because this needs modifications in most cases. Calling a separate file works best, and the code can stay structured with linebreaks... no wait, Dorian improved KM75 so that it can have linebreaks inside kmm-files too!! grinning smiley

Too bad I can't play with it myself yet, but wouldn't use it yet anyway in the next future as long as I need my macros to still work in older KM too smiling smiley But great improvement for future macros!

Options: ReplyQuote
Re: Converting Userscript to Macro
Posted by: Zero3K
Date: March 29, 2015 07:52PM

I want something that's like Javascriptia but can automatically apply scripts in a directory to URLs that are defined via @include(s) which are in them.

Options: ReplyQuote
Re: Converting Userscript to Macro
Posted by: siria
Date: March 30, 2015 11:27PM

Puhh... tough one. I could only try to scramble some workarounds together similar like "Open all Favorites in a folder" (macro Favinia) to get a list of the files. Meaning to get a file list of a folder, needs to open that folder as a webpage in the browser, with all files appearing as links, of which then a javascript can make a list of. That list of filenames would be stored in an ini-file between sessions. This initial get-list-command would have to be executed once when you add new scripts, started manually.

Then each time when a webpage has finished loading, the macro would read the content of the first userscript, crop the chapter with the @include-lines, compare if the current domain appears in that text block anywhere, if yes insert that file. Then it takes the next file, looks if current domain is in it, etc. etc.

Sounds like quite a performance eater to me, depending on number and size of files, and am sure a pro could write something that works a lot faster and with probably much slimmer code, and myself probably just not being the right person for this.

Anyway, the next prob is, macros can only insert scripts after a page has finished loading, not sure if that's always sufficient.

Further prob, how to disable single scripts?? Hm, well okay, just move them out of the folder so the macro finds no content... It's all just workarounds really, more or less working and awkward...

And another prob, would it work at all??
Have you tried if your scripts work with StyleonMini, especially those bigger as 32kB, and especially in KM75??

And when I'd finally have it halfway working, someone will come with a fixed greasemonkey that does it all much better tongue sticking out smiley

Options: ReplyQuote


K-Meleon forum is powered by Phorum.