Страницы: 1
Page Encoding (Firefox 13+)
Автор: okkamas_knife, init
Описание: Кнопка основана на оригинальной кнопке Page Encoding из этого поста, которая в Firefox 13 больше не работает.
В этой версии исправлена работа кнопки в Firefox 13, также теперь в выпадающем меню автоматически показывается текущая кодировка страницы, если она есть в списке.
custombutton://%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3Ccustombutton%20xmlns%3Acb%3D%22http%3A//xsms.nm.ru/custombuttons/%22%3E%0A%20%20%3Cname%3EPage%20Encoding%3C/name%3E%0A%20%20%3Cimage%3E%3C%21%5BCDATA%5Bdata%3Aimage/gif%3Bbase64%2CR0lGODdhEAAQAPcAAGxiJLSuVMzaHIyKXJyu5JSKpLTa/Ly2xNza5FxapJyWtKzG/OTu/HRynLSuvHSC/PT6/LTKRJy6/Mzi/MzGrISW/GRavKSefGxy9HyO/HRmhJy2/KzS/PTy7LzOZJSu9JSSvMTe/LzC3Nzm/GxqlIym/KSeVGxitKSezIR+nHyK9Pz69NTq/NTO1Iye9HxuhJyy/MS+VNz+dJSKtLza/GRipKSapKzO/Ozu9HxylKzC/MTSHKTC/NTm/HRq1KSenHx+1ISS9HxqjLTS/PT27NTWhJSy/MS+zOTm9Pz+/NTS3HRuRLSyfMziVJSSVJSOpLy61Nze5GRapLSyzHyG/KS+/Mzm/ISa/GxizKymdHRqhPTy9LzSXJSu/JSSzMTi/Nzq/KSmPHyK/Pz6/NTO3Iye/Lze/KSarLTO/Ozy/Hx2nMzWHIR+1ISS/LTW/MTCzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAEAAQAAAITQDhCBxIsKDAFggTKlR4cKFDhA3htJA4cOLBiBMhaoQoMWPHjyA5ftxo8eHDhgs7MqSYUOXIix49soQ5U2bJmDgpqjTZcidPiwaDCgwIADs%3D%5D%5D%3E%3C/image%3E%0A%20%20%3Cmode%3E0%3C/mode%3E%0A%20%20%3Cinitcode%3E%3C%21%5BCDATA%5Bvar%20ddMenu%20%3D%0A%3Cmenupopup%20xmlns%3D%22http%3A//www.mozilla.org/keymaster/gatekeeper/there.is.only.xul%22%0A%09%20%20%20oncommand%3D%22this.parentNode.setDocEncoding%28event%29%22%3E%0A%09%3Cmenuitem%20type%3D%22radio%22%20charset%3D%22KOI8-R%22%20label%3D%22%u041A%u0438%u0440%u0438%u043B%u043B%u0438%u0446%u0430%20%28KOI8-R%29%22/%3E%0A%09%3Cmenuitem%20type%3D%22radio%22%20charset%3D%22windows-1251%22%20label%3D%22%u041A%u0438%u0440%u0438%u043B%u043B%u0438%u0446%u0430%20%28Windows-1251%29%22/%3E%0A%09%3Cmenuitem%20type%3D%22radio%22%20charset%3D%22IBM866%22%20label%3D%22%u041A%u0438%u0440%u0438%u043B%u043B%u0438%u0446%u0430/%u0420%u043E%u0441%u0441%u0438%u044F%20%28CP-866%29%22/%3E%0A%09%3Cmenuitem%20type%3D%22radio%22%20charset%3D%22UTF-8%22%20label%3D%22Unicode%20%28UTF-8%29%22/%3E%0A%3C/menupopup%3E%3B%0AddMenu%20%3D%20new%20DOMParser%28%29.parseFromString%28ddMenu.toXMLString%28%29%2C%22application/xml%22%29.documentElement%3B%0Athis.orient%20%3D%20%22horizontal%22%3B%0Athis.type%20%3D%20%22menu%22%3B%0Athis.appendChild%28ddMenu%29%3B%0Athis.setDocEncoding%20%3D%20function%28evt%29%20%7B%0A%09var%20_charset%20%3D%20evt.target.getAttribute%28%22charset%22%29%3B%0A%09try%20%7B%0A%09%09SetForcedCharset%28_charset%29%3B%0A%09%7D%20catch%28e%29%20%7B%0A%09%09BrowserSetForcedCharacterSet%28_charset%29%3B%0A%09%7D%0A%7D%0AgetDocEncoding%20%3D%20function%28%29%20%7B%0A%09var%20docCharset%20%3D%20getBrowser%28%29.docShell.QueryInterface%28Components.interfaces.nsIDocCharset%29%3B%0A%09var%20curChar%20%3D%20docCharset.charset%3B%0A%09switch%20%28curChar%29%20%7B%0A%09%09case%20%22KOI8-R%22%3A%20ddMenu.childNodes%5B1%5D.setAttribute%28%22checked%22%2C%20%22true%22%29%3B%20break%3B%0A%09%09case%20%22windows-1251%22%3A%20ddMenu.childNodes%5B3%5D.setAttribute%28%22checked%22%2C%20%22true%22%29%3B%20break%3B%0A%09%09case%20%22IBM866%22%3A%20ddMenu.childNodes%5B5%5D.setAttribute%28%22checked%22%2C%20%22true%22%29%3B%20break%3B%0A%09%09case%20%22UTF-8%22%3A%20ddMenu.childNodes%5B7%5D.setAttribute%28%22checked%22%2C%20%22true%22%29%3B%20break%3B%0A%09%09default%3A%20ddMenu.childNodes%5B1%5D.removeAttribute%28%22checked%22%29%3B%20ddMenu.childNodes%5B3%5D.removeAttribute%28%22checked%22%29%3B%20ddMenu.childNodes%5B5%5D.removeAttribute%28%22checked%22%29%3B%20ddMenu.childNodes%5B7%5D.removeAttribute%28%22checked%22%29%3B%0A%09%7D%0A%7D%0Athis.setAttribute%28%27onclick%27%2C%20%22getDocEncoding%28%29%3B%22%29%3B%0A%5D%5D%3E%3C/initcode%3E%0A%20%20%3Ccode%3E%3C%21%5BCDATA%5B/*Code*/%0A%5D%5D%3E%3C/code%3E%0A%20%20%3Caccelkey%3E%3C%21%5BCDATA%5B%5D%5D%3E%3C/accelkey%3E%0A%20%20%3Chelp%3E%3C%21%5BCDATA%5B%5D%5D%3E%3C/help%3E%0A%20%20%3Cattributes/%3E%0A%3C/custombutton%3E
Код инициализации:
var ddMenu = <menupopup xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" oncommand="this.parentNode.setDocEncoding(event)"> <menuitem type="radio" charset="KOI8-R" label="Кириллица (KOI8-R)"/> <menuitem type="radio" charset="windows-1251" label="Кириллица (Windows-1251)"/> <menuitem type="radio" charset="IBM866" label="Кириллица/Россия (CP-866)"/> <menuitem type="radio" charset="UTF-8" label="Unicode (UTF-8)"/> </menupopup>; ddMenu = new DOMParser().parseFromString(ddMenu.toXMLString(),"application/xml").documentElement; this.orient = "horizontal"; this.type = "menu"; this.appendChild(ddMenu); this.setDocEncoding = function(evt) { var _charset = evt.target.getAttribute("charset"); try { SetForcedCharset(_charset); } catch(e) { BrowserSetForcedCharacterSet(_charset); } } getDocEncoding = function() { var docCharset = getBrowser().docShell.QueryInterface(Components.interfaces.nsIDocCharset); var curChar = docCharset.charset; switch (curChar) { case "KOI8-R": ddMenu.childNodes[1].setAttribute("checked", "true"); break; case "windows-1251": ddMenu.childNodes[3].setAttribute("checked", "true"); break; case "IBM866": ddMenu.childNodes[5].setAttribute("checked", "true"); break; case "UTF-8": ddMenu.childNodes[7].setAttribute("checked", "true"); break; default: ddMenu.childNodes[1].removeAttribute("checked"); ddMenu.childNodes[3].removeAttribute("checked"); ddMenu.childNodes[5].removeAttribute("checked"); ddMenu.childNodes[7].removeAttribute("checked"); } } this.setAttribute('onclick', "getDocEncoding();");
Отредактировано init (26-06-2012 14:43:30)
Отсутствует
Кнопка не работает в Firefox 20 и выше.
Работающий вариант кода (получен автоматически с помощью кнопки Convert_E4X):
var ddMenu = '<menupopup xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"\n\ oncommand="this.parentNode.setDocEncoding(event)">\n\ <menuitem type="radio" charset="KOI8-R" label="Кириллица (KOI8-R)"/>\n\ <menuitem type="radio" charset="windows-1251" label="Кириллица (Windows-1251)"/>\n\ <menuitem type="radio" charset="IBM866" label="Кириллица/Россия (CP-866)"/>\n\ <menuitem type="radio" charset="UTF-8" label="Unicode (UTF-8)"/>\n\ </menupopup>'; ddMenu = new DOMParser().parseFromString(ddMenu,"application/xml").documentElement; this.orient = "horizontal"; this.type = "menu"; this.appendChild(ddMenu); this.setDocEncoding = function(evt) { var _charset = evt.target.getAttribute("charset"); try { SetForcedCharset(_charset); } catch(e) { BrowserSetForcedCharacterSet(_charset); } } getDocEncoding = function() { var docCharset = getBrowser().docShell.QueryInterface(Components.interfaces.nsIDocCharset); var curChar = docCharset.charset; switch (curChar) { case "KOI8-R": ddMenu.childNodes[1].setAttribute("checked", "true"); break; case "windows-1251": ddMenu.childNodes[3].setAttribute("checked", "true"); break; case "IBM866": ddMenu.childNodes[5].setAttribute("checked", "true"); break; case "UTF-8": ddMenu.childNodes[7].setAttribute("checked", "true"); break; default: ddMenu.childNodes[1].removeAttribute("checked"); ddMenu.childNodes[3].removeAttribute("checked"); ddMenu.childNodes[5].removeAttribute("checked"); ddMenu.childNodes[7].removeAttribute("checked"); } } this.setAttribute('onclick', "getDocEncoding();");
Отсутствует
Страницы: 1