exsidas
BANNED | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору // Кнопка для управления масштабом страницы в адресной строке, от 24.11.2016. .......................... (()=> { // Удалить из адресной строки FF51 стандартную кнопку масштаба .... var but = document.getElementById('urlbar-zoom-button'); if (but) but.style.display = "none"; // Создать в адресной строке кнопку масштаба .... var zoomButton = document.createElement("statusbarpanel"); var urlbarIcons = document.getElementById("urlbar-icons"); urlbarIcons.insertBefore(zoomButton, urlbarIcons.lastChild); // перед последней кнопкой адресной строки addDestructor(()=> zoomButton.remove()); updateZoomButton(); zoomButton.id = "zoomButton"; zoomButton.tooltipText = "Л: Менять масштаб страницы или только текста\nС: Единый масштаб для всех страниц \nП: Сбросить масштаб на 100% "; // Отслеживать клики на кнопке масштаба .... addEventListener("click", e=> { if ( e.button == 0 ) ZoomManager.toggleZoom(); // переключить режим изминения масштаба if ( e.button == 1 ) { // единый масштаб для всех страниц cbu.isPref("CB.zoom.allEvenly", false); cbu.setPrefs("CB.zoom.allEvenly", !cbu.getPrefs("CB.zoom.allEvenly") ); cbu.setPrefs("CB.zoom.Percent", ZoomManager.zoom.toFixed(2) ); updateZoomButton(); } if ( e.button == 2 ) { e.preventDefault(); FullZoom.reset(); }; // сбросить масштаб }, false, zoomButton); // Менять масштаб колесиком мыши на кнопке масштаба .... addEventListener("DOMMouseScroll", e=> { e.detail > 0 ? FullZoom.reduce() : FullZoom.enlarge(); }, false, zoomButton); // Следим за изменением масштаба и запускаем обновление кнопки .... var str = "{ setTimeout(()=> { updateZoomButton() }, 50);"; var handleEvent = parseInt(Services.appinfo.version) > 33 ? FullZoom.handleEvent : FullZoom._handleMouseScrolled; var array = [FullZoom.reset, FullZoom.reduce, FullZoom.enlarge, ZoomManager.toggleZoom, handleEvent]; array.forEach(func=> { setTimeout(()=> { eval( (func.toString().replace('_', '.').match(/function ([^(]*)\(/)[1] + " = " + func.toString().replace("{", str)) )}, 50) }); addDestructor(()=> { array.forEach(func=> { eval( (func.toString().replace('_', '.').match(/function ([^(]*)\(/)[1] + " = " + func.toString()).replace(str,"{") ) }); }); // Показывать текущий масштаб страницы на кнопке и изменять цвет и шрифт отображения масштаба .... function updateZoomButton(e) { zoomButton.label = Math.round(ZoomManager.zoom*100) + "%"; setTimeout(()=> { zoomButton.style.fontWeight = ZoomManager.useFullZoom ? '' : 'bold'; zoomButton.style.color = cbu.getPrefs("CB.zoom.allEvenly") ? "red" : ""; }, 5); // запомнить текущий масштаб в 'about:config' if ( e == undefined ) { try { window.clearTimeout(zoomButton.prefTimeout) } catch(e) {}; zoomButton.prefTimeout = window.setTimeout(()=> { cbu.setPrefs("CB.zoom.Percent", ZoomManager.zoom.toFixed(2) ) }, 250); } }; // Устанавливать единый масштаб для всех страниц если это разрешено в 'about:config' .... addEventListener("TabAttrModified", e=> { if ( e.target.linkedBrowser.currentURI.spec !== gBrowser.currentURI.spec ) return; if ( cbu.getPrefs("CB.zoom.allEvenly") && content.location.protocol.startsWith("http") ) { var value = cbu.getPrefs("CB.zoom.Percent"); if ( ZoomManager.zoom.toFixed(2) == value ) return; setTimeout(()=> { gBrowser.markupDocumentViewer[ZoomManager.useFullZoom ? 'fullZoom' : 'textZoom'] = value; updateZoomButton(e); }, 0); } else updateZoomButton(e); }, true, gBrowser.tabContainer); })(); |