Extensions :  K-Meleon Web Browser Forum
All about K-Meleon extensions. 
KillAnim UPDATE may-29 (stop animated gif images and whole page)
Posted by: siria
Date: May 24, 2011 11:48PM

Man!! Can't believe how easy that is, after struggling for such a long time and searching around and messing macros and workarounds without success. And now it turns out there's just 1 simple line needed! *dropdead*
Continued from here http://kmeleonbrowser.org/forum/read.php?1,104538,page=2
___________________________________________

K-Meleon has a default setting for animated gifs: Play normal, or 1x, or not (=static image). But after a page was already loaded, already animated gifs can't be stopped anymore (KM1.6b2 + older). This macro allows to STOP all already running animated gifs after a page was already loaded.
___________________________________________

It works beautifully on the "Block Animation" button now, instantly and without any scrolling smiling smiley
Actually, it isn't specifically to stop animation, but to stop the whole page!
Whatever else that stops... scripts obviously not... perhaps I should rename it?

Hmm, funny... Now when hitting the "Block Animation" (=alternative STOP) Button, a currently loading page stops in the middle, that's okay, but the already loaded gifs are still shown moving. Toggling the button ON/OFF again now stops the animations too! Does it have to be fired 2x??

PS: For testing or whatever, you can also just use this as a bookmarklet:
javascript:window.stop()

PS2: The keyboard shortcut (Shift+ESC) works sometimes and other times not, no idea why?
___________________________________________

"Installation": Copy the blue text into a new text file, and save it as "KillAnim.kmm" into one of your macros folders. Must NOT have a .txt ending. Restart browser.
___________________________________________


# K-Meleon Macros (http://kmeleon.sourceforge.net/wiki/index.php?id=MacroLanguage2)
#
# ----------------------------- KillAnim.kmm --------------------------
# K-Meleon has a default setting for animated gifs: Play normal, or 1x, or not (=static image)
# But after a page was already loaded, already animated gifs can't be stopped anymore (KM1.6b2 + older)
# This macro allows to STOP already running animated gifs (1 or all) after a page was already loaded.
# Note: UN-blocking will NOT re-animate them, once killed they'll stay dead until the page is reloaded again ;-)
#
# VERSION: v4.01 / 2011-05-29 (by siria)
#
# MENUS:
# Right-click any image > Kill Animation (1 or all)
# Or click Tools > Privacy > "Kill Animation" or "Block Animation", or the Animation Button in Privacy Toolbar

# Forum: kmeleon.sf.net/forum/read.php?9,116553
#----------------------------------------------------------------------------
#
# TIP: If you use the lovely Privacy Toolbar, add the "Kill" menu (Flash, Java, Animations)
# as right-click context menu on a button, e.g. on the "Kill Flash" button
, or the Animation button:
# Edit > Configuration > Toolbars
# Example for Flash: Replace "macros(JS_killFlash)" with "macros(JS_killFlash)|_Privacy_Kill"
# Or example to add whole Privacy Menu on Animation button right-clicks:
# "macros(pref_ToggleAnimation)|&Privacy"

JS_killAnimation{
macroinfo=_("Stop all animated gif images in this page");
# If extension "Policy Manager" is used, allow this stop command
$pref_PolJS="capability.policy.default.javascript.enabled";
$_bak=getpref(STRING,$pref_PolJS);
$_bak=="noAccess" ? setpref(STRING,$pref_PolJS,"allAccess"):0;
injectJS("window.stop()");
$_bak=="noAccess" ? setpref(STRING,$pref_PolJS,"noAccess"):0;
}

pref_ToggleAnimation{
macroinfo=_("Toggle image animation");
menuchecked=(getpref(STRING,$pref_Animation)=="none");
togglepref(STRING,$pref_Animation,"normal","none"); &_pref_SyncButtons;
statusbar(sub("%s",getpref(STRING,$pref_Animation)=="none"?$off:$on,_("Image animation %s")));
##### mod. by siria
getpref(STRING,$pref_Animation)=="none" ? &JS_killAnimation : 0;
}

# Next one is still the long-winded old workaround from v2, to stop just 1 image:

KillAnim_1image{
macroinfo="Kill 1 image animation (workaround, sorry, some sites don't work. Opens single image then navigates back and reloads from cache)";
$_killanim1bak=getpref(STRING,"image.animation_mode");
$_killanim2bak=getpref(INT,"browser.cache.check_doc_frequency");
setpref(STRING,"image.animation_mode","none");
setpref(INT,"browser.cache.check_doc_frequency",2);
open($ImageURL);
$OnLoadOnce=$OnLoadOnce."_KillAnim_1imageB;";
}
_KillAnim_1imageB{
id(ID_NAV_BACK);
setpref(STRING,"image.animation_mode",$_killanim1bak);
setpref(INT,"browser.cache.check_doc_frequency",$_killanim2bak);
&_pref_SyncButtons;
}

_KillAnim_BuildMenu{
# Keyboard shortcut: Shift+ESC (not sure if it works?)
setaccel("SHIFT VK_ESCAPE","macros(JS_killAnimation)");
#
setmenu(_Privacy_Kill,macro,"Kill Animation",JS_killAnimation,-1);
setmenu("ImageView",macro,"Kill Animation (Stop page)",JS_killAnimation,-1);
setmenu("ImageView",macro,"Kill Animation (Stop 1)",KillAnim_1image,-1);
# Optional: If you also want it on the context menu (right-click) of the Reload button:
# setmenu("Reloa&ding",macro,"Kill Animation (Stop)",JS_killAnimation,-1);
}

#--------------------- BROWSER START ----------------------
$OnInit=$OnInit."_KillAnim_BuildMenu;";
$macroModules=$macroModules."KillAnim;";




Edited 15 time(s). Last edit at 05/30/2011 07:05PM by siria.

Options: ReplyQuote
Re: KillAnim (stop animated gif images)
Posted by: JamesD
Date: May 25, 2011 12:30PM

Quote
siria
PS2: Does the keyboard shortcut (Shift+ESC) work for anyone, or is it just my old system having a little hickup at the moment?

Shift+ESC works on my KM 1.6.0 beta2 on Win 7 (32 bit).

Options: ReplyQuote
Re: KillAnim (stop animated gif images)
Posted by: JamesD
Date: May 25, 2011 06:38PM

@ siria

Great work on this macro. Took me a while to get it working. Was not your fault. Rather was problem with my system. I use Policy Manager plus a self made on/off for Javascript called FlipPM. I found that I had to insert some code in your macro so that my system would function correctly.

JS_killAnimation{
macroinfo=_("Stop all animated gif images in this page");
alert("JS_killAnimation is running");
$FlipFlip = false;
getpref( STRING, "capability.policy.default.javascript.enabled")=="noAccess" ? $FlipFlip=true : 0 ; 
$FlipFlip == true ? togglepref( STRING, "capability.policy.default.javascript.enabled", "noAccess", "allAccess") : 0;
injectJS("window.stop()");
$FlipFlip == true ? togglepref( STRING, "capability.policy.default.javascript.enabled", "noAccess", "allAccess") : 0;
}

The pink color lines I added to get around the Javascript thing.

Regarding the SHIFT + ESC, perhaps I was hasty in saying that it works. It seem to work only sometimes. I added the blue line of code in order to see if the SHIFT + ESC started the code. It does not always work.

Options: ReplyQuote
Re: KillAnim (stop animated gif images and whole page)
Posted by: siria
Date: May 26, 2011 06:23AM

Very interesting, thanks James! smiling smiley
Ah yeah, policy manager again, sigh. That's the problem with it, that lots of simple KM macro commands don't work, incl. even native ones like zoom options. Really a pity. That's why I prefer the "normal" javascript block from the privacy options, although that one again, it doesn't allow a whitelist for JS sites, sigh again! Not easy, all that exceptions stuff, oh well.
But your policy toggle is a great idea!

Have updated the code now, in theory no prob, but no time yet for testing at the moment.

Now that thing with the moody keyboard shortcut is still a mystery...



Edited 1 time(s). Last edit at 05/26/2011 07:02AM by siria.

Options: ReplyQuote
Re: KillAnim UPDATE may-26 (stop animated gif images and whole page)
Posted by: deadlock
Date: May 29, 2011 10:34PM

Quote
siria
Man!! Can't believe how easy that is, after struggling for such a long time and searching around and messing macros and workarounds without success. And now it turns out there's just 1 simple line needed! *dropdead*

Thank you so much Siria!

"For such a long time ..."

Options: ReplyQuote


K-Meleon forum is powered by Phorum.