|
发表于 2024-1-15 22:45:30
|
显示全部楼层
我觉得通过浏览器实现类似的功能很麻烦,很难仅通常简单的缩放操作来细化区分到域名级别以下的路径,况且不同网站的子域名及路径规则各异。
对于你这种需求,我个人更推荐编写类似如下的油猴脚本实现会更为方便:
- // ==UserScript==
- // @name Custom Zoom
- // @namespace cent_browser
- // @version 0.1.0
- // @description Customize the scaling of each webpage
- // @author You
- // @match *://*/*
- // @license GNU General Public License v3.0 or later
- // @grant GM_addStyle
- // @run-at document-start
- // ==/UserScript==
- (function () {
- class ZoomHandler {
- constructor() {
- this.rules = {
- 'www.ixigua.com': [{
- match: /\/\d+$/,
- value: 1.15
- }, {
- match: '*',
- value: 0.85
- }]
- };
- }
- handle(source) {
- const rule = this.rules[source.hostname];
- if (rule) {
- for (const item of rule) {
- if (this.match(item, source.pathname)) {
- this.setBodyZoom(item.value);
- break;
- }
- }
- }
- }
- match(ruleItem, pathname) {
- if (typeof ruleItem.match === 'string') {
- if (ruleItem.match === '*') {
- return true;
- } else {
- return ruleItem.match === pathname;
- }
- } else {
- return ruleItem.match.test(pathname);
- }
- }
- setBodyZoom(zoomValue = 1) {
- if (zoomValue) {
- GM_addStyle(`body {zoom: ${zoomValue};}`);
- console.info('[custom_zoom]: ' + zoomValue);
- }
- }
- }
- function main() {
- const zh = new ZoomHandler();
- zh.handle(location);
- }
- main();
- })();
复制代码
|
|