K-Meleon

KMeleonWiki > Resources > MacroLibrary > KmmExitTranslation

Exit Translation and Redirects v1.5

Submitted by: Siria

A macro to escape from Google Translations, babelfish, but also many other redirected URLs (not just translations).

NOTE: If a separate frame is on top of the page, the address in the URL bar usually never changes when surfing around. Then you may have to right-click in the frame below and first choose "Frame", then "EXIT Translation".

Version History:

2010-02-05 Version 1.5: New menu entry: Go-Button with "Paste And Go in New", replacing %-code in URL from clipboard

2010-01-29 Version 1.4: Added menu entries to replace %-codes in URLs, which sometimes produce "Page not found" errors. Find it by clicking on the Go-Button (for URL bar) or right-clicking on links.


Open your User Macro Folder (Edit > Configuration > User-Defined Macros) or your Macro Folder (Edit > Configuration > Macros) and create the following text file(s):

ExitTranslation.kmm

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

# -------------------------- ExitTranslation.kmm ---------------- v1.5 (2010-02-05 , by Siria)
# Dependencies: main.kmm
# Resources: -
# Preferences: -
# Menu entries "EXIT translation or redirects": Tools > Translation, or RIGHT-CLICK on a PAGE, or FRAME, or LINK
# Menu entries  "REPLACE %-CODE": on Go-Button (for URL) or RIGHT-CLICK on LINK
# Web + Forum: kmeleon.sf.net/wiki/KmmExitTranslation + kmeleon.sf.net/forum/read.php?9,100742
#--------------------
# VERSION 1.4:  New menu entries:  REPLACE %-CODES on Go-Button (for URL) or RIGHT-CLICK on LINK
# VERSION 1.5:  New menu entry: Go-Button with "Paste And Go in New", replacing %-code in URL from clipboard
#--------------------
#
# A macro to escape from Google Translations, babelfish, but also many other redirected URLs (not just translations).
# Instead of cleaning redirects, there can also just those pesky %-codes converted (%20=" " etc.)
# NOTE: If a separate frame is on top of the page, the URL usually never changes when surfing around.
# Then you may have to right-click in the frame below and first choose "Frame", then "EXIT Translation".

#================= CUSTOMIZING ====================
#
# BUTTON-command for toolbars.cfg : "macros(ExitTranslation_Page)|&Translation"
# BUTTON-tooltip e.g.: "EXIT from translation or other redirected URL (right-click for Translation menu)"
# MENUS: To change menu entries (position and text): Modify the setmenu-lines at the bottom
# OPEN IN NEW, OR in current tab, OR in background: Set "#" in front of 2 of the 3 "open"-lines below

#==================== CODE ========================

ExitTranslation_Page{
macroinfo="EXIT from forced translation or other redirect";
$OpenURL=$URL ;
&_ExitTranslation_extracturl;
open($OpenURL);
# &OpenURL_InNew;
# &OpenURL_InBg;
}

ExitTranslation_Frame{
macroinfo="EXIT from forced translation or other redirect";
$OpenURL=$FrameURL ;
&_ExitTranslation_extracturl;
open($OpenURL);
# &OpenURL_InNew;
# &OpenURL_InBg;
}

ExitTranslation_Link{
macroinfo="Open In New - EXIT from forced translation or other redirect";
$OpenURL=$LinkURL ;
&_ExitTranslation_extracturl;
# open($OpenURL);
&OpenURL_InNew;
# &OpenURL_InBg;
}

ExitTranslation_DecodePage{
macroinfo="URL: Replace %-codes";
$OpenURL=$URL ;
&_ExitTranslation_decode;
open($OpenURL);
}

ExitTranslation_DecodeLink{
macroinfo="Open link - Replace %-codes";
$OpenURL=$LinkURL ;
&_ExitTranslation_decode;
# open($OpenURL);
&OpenURL_InNew;
# &OpenURL_InBg;
}

ExitTranslation_GoPasteNew{
macroinfo=_("Get Clipboard, replace %-codes and open as URL in New Tab/Window");
$OpenURL=getclipboard();
&_ExitTranslation_decode;
&OpenURL_InNew;
}

_ExitTranslation_extracturl{
#  replace %-codes:
&_ExitTranslation_decode;
# cut at BEGINNING:
$OpenURL=substr($OpenURL,4);
index($OpenURL,"http")>-1 ? $OpenURL=substr($OpenURL,index($OpenURL,"http")) : 0;
index($OpenURL,"&url=")>-1 ? $OpenURL=substr($OpenURL,index($OpenURL,"&url=")+5) : 0;
# cut at ENDING: (&rurl=  &hl=  suffixes from google translate)
index($OpenURL,".htm&")>-1 ? $OpenURL=substr($OpenURL,0,index($OpenURL,".htm&")+4) : 0;
index($OpenURL,".html&")>-1 ? $OpenURL=substr($OpenURL,0,index($OpenURL,".html&")+5) : 0;
index($OpenURL,"&rurl=")>-1 ? $OpenURL=substr($OpenURL,0,index($OpenURL,"&rurl=")) : 0;
index($OpenURL,"&hl=")>-1 ? $OpenURL=substr($OpenURL,0,index($OpenURL,"&hl=")) : 0;
}

_ExitTranslation_decode{
#  replace %-codes:  can't take urldecode($OpenURL), it cuts beginning if url has "/ */http"
$OpenURL=gsub("%3a",":",$OpenURL); $OpenURL=gsub("%3A",":",$OpenURL);
$OpenURL=gsub("%2f","/",$OpenURL); $OpenURL=gsub("%2F","/",$OpenURL);
$OpenURL=gsub("%20"," ",$OpenURL);
$OpenURL=gsub("%26","&",$OpenURL);
$OpenURL=gsub("%3f","?",$OpenURL); $OpenURL=gsub("%3F","?",$OpenURL);
$OpenURL=gsub("%3d","=",$OpenURL); $OpenURL=gsub("%3D","=",$OpenURL);
}

# Modify your menu entries below. The entry text right after "macro" can freely be changed.
# The numbers in the end are the line position in the menu (0=on top, "-1" or nothing = at end)
# Set a # at the beginning to hide a menu entry.

_ExitTranslation_BuildMenu{
setmenu("&Translation",macro,"EXIT translation or redirect",ExitTranslation_Page,0);
setmenu("DocumentSave",macro,"EXIT translation or redirect",ExitTranslation_Page,-1);
setmenu("FrameSave",macro,"EXIT translation or redirect",ExitTranslation_Frame,-1);
setmenu("LinkOpen",macro,"Open In New - EXIT translation or redirect",ExitTranslation_Link,-1);
setmenu("LinkOpen",macro,"Open In New - Replace %-codes",ExitTranslation_DecodeLink,-1);
setmenu(_Go_Clipboard,macro,"URL: Replace %-codes",ExitTranslation_DecodePage,-1);
setmenu(_Go_Clipboard,macro,"Paste And Go in New Page",ExitTranslation_GoPasteNew,"Paste And &Search");
# setmenu("LinkSave",macro,"EXIT Translation - Open Link In New",ExitTranslation_Link,-1);
}

#------------------------ on browser start --------------------
$OnInit=$OnInit."_ExitTranslation_BuildMenu;";
$macroModules=$macroModules."ExitTranslation;"; 


Comments & Questions

K-Meleon

(c) 2000-2010 kmeleonbrowser.org. All rights reserved.
design by splif.