逗妇乳
小狐狸
小狐狸
  • UID50148
  • 注册日期2015-06-01
  • 最后登录2022-11-21
  • 发帖数83
  • 经验89枚
  • 威望0点
  • 贡献值32点
  • 好评度6点
阅读:1437回复:9

求大神修复UC脚本 Styloaix

楼主#
更多 发布于:2020-10-18 22:45
是一个用户CSS加载工具,支持浏览器界面覆盖,相当于以前的Stylish
现在问题是这个脚本无法二次编辑已经保存的样式,打开空白,大佬能给修复一下吗?
脚本源码地址  https://github.com/xiaoxiaoflood/firefox-scripts/blob/master/chrome/styloaix.uc.js
kidzgy
火狐狸
火狐狸
  • UID35190
  • 注册日期2011-02-03
  • 最后登录2023-01-31
  • 发帖数235
  • 经验181枚
  • 威望0点
  • 贡献值114点
  • 好评度16点
1楼#
发布于:2021-04-03 23:03
从别处淘来的脚本,可以试一下
// ==UserScript==
// @name            StyloaiX 用户样式管理
// @author          xiaoxiaoflood
// @include         main
// @include         chrome://userchromejs/content/styloaix/edit.xhtml
// @shutdown        UC.styloaix.destroy();
// @onlyonce
// ==/UserScript==
 
// inspired by legacy Stylish and https://github.com/Endor8/userChrome.js/blob/master/Updates%202019/UserCSSLoader.uc.js
// editor forked from Stylish - minor changes to edit.xhtml, but edit.js almost completely rewritten, with improvements and bug fixes.
// icon from old Stylish
 
// search for "userChromeJS.styloaix" in about:config to change settings.
 
(function () {
 
  UC.styloaix = {
    init: function () {
      xPref.lock(this.PREF_MOZDOCUMENT, true);
      xPref.set(this.PREF_DISABLED, false, true);
      xPref.set(this.PREF_STYLESDISABLED, '[]', true);
      xPref.set(this.PREF_INSTANTCHECK, true, true);
      xPref.set(this.PREF_INSTANTPREVIEW, true, true);
      xPref.set(this.PREF_INSTANTINTERVAL, 500, true);
      xPref.set(this.PREF_LINEWRAPPING, true, true);
      xPref.set(this.PREF_OPENINWINDOW, true, true);
 
      this.prefListener = xPref.addListener(this.PREF_STYLESDISABLED, (sDisabled) => {
        let newSet;
        try {
          newSet = new Set(JSON.parse(sDisabled));
        } catch {
          xPref.set(this.PREF_STYLESDISABLED, JSON.stringify([...this.disabledStyles]));
          return;
        }
 
        this.styles.forEach(style => {
          if ((style.enabled && newSet.has(style.fullName)) ||
              (!style.enabled && !newSet.has(style.fullName)))
            this.toggleStyle(style);
        });
      });
      this.prefListenerAll = xPref.addListener(this.PREF_DISABLED, (disabled) => {
        this.toggleAll({disable: disabled});
        this.btnClasses.reverse();
        _uc.windows((doc) => {
          let enabledBtn = doc.getElementById('styloaix-enabled');
          enabledBtn.label = disabled ? '已禁用' : '已启用';
          enabledBtn.setAttribute('checked', !disabled);
          doc.getElementById('styloaix-button').classList.replace(...this.btnClasses);
        });
      });
 
      this.disabledStyles = new DisabledSet(JSON.parse(xPref.get(this.PREF_STYLESDISABLED)).sort((a, b) => a[0].localeCompare(b[0])));
 
      this.UserStyle = UserStyle;
 
      if (!this.enabled)
        this.btnClasses.reverse();
 
      this.loadStyles();
 
      CustomizableUI.createWidget({
        id: 'styloaix-button',
        type: 'custom',
        defaultArea: CustomizableUI.AREA_NAVBAR,
        onBuild: (doc) => {
          let btn = _uc.createElement(doc, 'toolbarbutton', {
            id: 'styloaix-button',
            label: 'StyloaiX',
            tooltiptext: 'StyloaiX 用户样式管理',
            type: 'menu',
            class: 'toolbarbutton-1 chromeclass-toolbar-additional ' + this.btnClasses[1],
            onclick: 'if (event.button === 1 && event.target.id == this.id) UC.styloaix.enabled = !UC.styloaix.enabled;'
          });
 
          let popup = _uc.createElement(doc, 'menupopup', {id: 'styloaix-popup'});
          btn.appendChild(popup);
 
          let disabled = xPref.get(this.PREF_DISABLED);
          let toggleBtn = _uc.createElement(doc, 'menuitem', {
            id: 'styloaix-enabled',
            label: disabled ? '已禁用' : '已启用',
            type: 'checkbox',
            checked: !disabled,
            oncommand: 'UC.styloaix.enabled = !UC.styloaix.enabled;'
          });
          popup.appendChild(toggleBtn);
           
          let menuseparator = _uc.createElement(doc, 'menuseparator');
          popup.appendChild(menuseparator);
 
          let reloadAllBtn = _uc.createElement(doc, 'menuitem', {
            id: 'styloaix-reload-all',
            label: '重新载入所有样式',
            oncommand: 'UC.styloaix.toggleAll({reload: true});'
          });
          popup.appendChild(reloadAllBtn);
 
          let openFolderBtn = _uc.createElement(doc, 'menuitem', {
            id: 'styloaix-open-folder',
            label: '打开样式文件夹',
            oncommand: 'UC.styloaix.CSSDIR.launch();'
          });
          popup.appendChild(openFolderBtn);
 
          let newStyleMenu = _uc.createElement(doc, 'menu', {
            id: 'styloaix-new-style',
            label: '新建样式'
          });
 
          let newStylePopup = _uc.createElement(doc, 'menupopup', {id: 'styloaix-newstyle-popup'});
 
          let newPageStyleBtn = _uc.createElement(doc, 'menuitem', {
            label: '当前页面',
            oncommand: 'UC.styloaix.openEditor({url: gBrowser.currentURI.specIgnoringRef, type: "url"});'
          });
          newStylePopup.appendChild(newPageStyleBtn);
 
          let newSiteStyleBtn = _uc.createElement(doc, 'menuitem', {
            label: '当前站点',
            oncommand: 'let host = gBrowser.currentURI.asciiHost; UC.styloaix.openEditor({url: host || gBrowser.currentURI.specIgnoringRef, type: host ? "domain" : "url"});'
          });
          newStylePopup.appendChild(newSiteStyleBtn);
 
          let newStyle = _uc.createElement(doc, 'menuitem', {
            label: '空白样式',
            oncommand: 'UC.styloaix.openEditor();'
          });
          newStylePopup.appendChild(newStyle);
 
          newStyleMenu.appendChild(newStylePopup);
          popup.appendChild(newStyleMenu);
 
          let separatorBeforeStyles = _uc.createElement(doc, 'menuseparator');
          separatorBeforeStyles.hidden = !this.styles.size;
          popup.appendChild(separatorBeforeStyles);
          btn._separator = separatorBeforeStyles;
 
          let stylePopup = _uc.createElement(doc, 'menupopup', {id: 'styloaix-style-context'});
 
          let styleEdit = _uc.createElement(doc, 'menuitem', {
            id: 'styloaix-style-edit',
            label: '编辑',
            oncommand: 'UC.styloaix.openEditor({id: document.popupNode._style.fullName})'
          });
          stylePopup.appendChild(styleEdit);
 
          let styleReload = _uc.createElement(doc, 'menuitem', {
            id: 'styloaix-style-reload',
            label: '重载',
            oncommand: 'document.popupNode._style.reload()'
          });
          stylePopup.appendChild(styleReload);
 
          let styleDelete = _uc.createElement(doc, 'menuitem', {
            id: 'styloaix-style-delete',
            label: '删除',
            oncommand: 'document.popupNode._style.delete()'
          });
          stylePopup.appendChild(styleDelete);
 
          doc.getElementById('mainPopupSet').appendChild(stylePopup);
 
          this.styles.forEach(style => {
            this.addStyleInMenu(style, popup);
          });
 
          return btn;
        }
      });
 
      _uc.sss.loadAndRegisterSheet(this.STYLE.url, this.STYLE.type);
    },
 
    get enabled () {
      return !xPref.get(this.PREF_DISABLED);
    },
 
    set enabled (val) {
      xPref.set(this.PREF_DISABLED, !val);
    },
 
    loadStyles: function() {
      let files = this.CSSDIR.directoryEntries.QueryInterface(Ci.nsISimpleEnumerator);
      while (files.hasMoreElements()) {
        let file = files.getNext().QueryInterface(Ci.nsIFile);
        if (file.leafName.endsWith('.css')) {
          let style = new UserStyle(file);
        }
      }
 
      if (this.enabled)
        this.toggleAll({disable: false});
 
      this.rebuildMenu();
    },
 
    toggleAll: function ({disable = this.enabled, reload = false} = {}) {
      this.styles.forEach(style => {
        if (style.enabled)
          this.toggleStyle(style, {aStatus: !disable, changeStatus: false, forced: true});
      });
      if (reload) {
        this.styles = new Map();
        this.loadStyles();
      }
    },
 
    toggleStyle: function (style, {aStatus = !style.enabled, changeStatus = true, forced = false} = {}) {
      if (this.enabled || forced) {
        if (aStatus)
          style.register();
        else
          style.unregister();
      }
      if (changeStatus) {
        this.changeStatus(style, aStatus);
      }
    },
 
    changeStatus: function (style, aStatus) {
      style.enabled = aStatus;
      _uc.windows((doc) => {
        let menuitem = doc.getElementById('styloaix-popup').getElementsByAttribute('styleid', style.fullName)[0];
        menuitem.setAttribute('checked', aStatus);
      });
      if (aStatus) {
        this.disabledStyles.delete(style.fullName);
      } else {
        this.disabledStyles.add(style.fullName);
      }
    },
 
    addStyleInMenu (style, popup) {
      let menuitem = _uc.createElement(popup.ownerDocument, 'menuitem', {
        label: style.name,
        type: 'checkbox',
        class: 'styloaix-style' + (style.type == _uc.sss.AUTHOR_SHEET ?
                                     '' :
                                     ' styloaix-' + (style.type == _uc.sss.USER_SHEET ?
                                       'user' :
                                       'agent') + 'sheet'),
        checked: style.enabled,
        context: 'styloaix-style-context',
        oncommand: 'UC.styloaix.toggleStyle(this._style);',
        styleid: style.fullName
      });
      menuitem.addEventListener('click', function (e) {
        if (e.button == 1)
          UC.styloaix.toggleStyle(this._style);
      });
      popup.appendChild(menuitem);
      menuitem._style = style;      
    },
 
    rebuildMenu () {
      let buttons = this.buttons;
      if (buttons.length) {
        buttons.forEach(btn => {
          let styles = btn.getElementsByClassName('styloaix-style');
          while (styles.length) {
            styles[0].remove();
          }
        })
      }
 
      let sortedMap = new Map([...this.styles.entries()].sort((a, b) => a[0].localeCompare(b[0])));
      sortedMap.forEach(style => {
        buttons.forEach(btn => {
          this.addStyleInMenu(style, btn.menupopup);
        });
      });
    },
 
    openEditor ({id, url, type} = {}) {
      let win = Services.wm.getMostRecentBrowserWindow();
      if (xPref.get(this.PREF_OPENINWINDOW)) {
        win.openDialog(this.EDITOR_URI, (id || win.Math.random()) + ' - StyloaiX Editor', 'centerscreen,chrome,resizable,dialog=no', {id, url, type});
      } else {
        let appendUrl = '';
        if (id != undefined)
          appendUrl = '?id=' + id;
        else if (url)
          appendUrl = '?url=' + encodeURIComponent(url) + '&type=' + type;
        win.switchToTabHavingURI(this.EDITOR_URI + appendUrl, true);
      }
    },
 
    get CSSDIR () {
      let cssFolder = _uc.chromedir.clone();
      cssFolder.append('UserStyles');
      if (!cssFolder.exists() || !cssFolder.isDirectory())
        cssFolder.create(Ci.nsIFile.DIRECTORY_TYPE, 0664);
      return this.CSSDIR = cssFolder;
    },
 
    btnClasses: ['icon-white', 'icon-colored'],
 
    get buttons () {
      let arr = [];
      let widget = CustomizableUI.getWidget('styloaix-button');
      if (widget && 'label' in widget) {
        widget.instances.forEach(btnWidget => {
          let btn = btnWidget.node;
          btn._separator.hidden = !this.styles.size;
          arr.push(btn);
        });
      }
      return arr;
    },
 
    PREF_DISABLED: 'userChromeJS.styloaix.allDisabled',
    PREF_STYLESDISABLED: 'userChromeJS.styloaix.stylesDisabled',
    PREF_INSTANTCHECK: 'userChromeJS.styloaix.instantCheck',
    PREF_INSTANTPREVIEW: 'userChromeJS.styloaix.instantPreview',
    PREF_INSTANTINTERVAL: 'userChromeJS.styloaix.instantInterval',
    PREF_OPENINWINDOW: 'userChromeJS.styloaix.openInWindow',
    PREF_LINEWRAPPING: 'userChromeJS.styloaix.lineWrapping',
    PREF_MOZDOCUMENT: 'layout.css.moz-document.content.enabled',
    EDITOR_URI: 'chrome://userchromejs/content/styloaix/edit.xhtml',
 
    STYLE: {
      url: Services.io.newURI('data:text/css;charset=UTF-8,' + encodeURIComponent(`
        @-moz-document url('${_uc.BROWSERCHROME}') {
          #styloaix-button.icon-white {
            list-style-image: url('chrome://userchromejs/content/styloaix/16w.png');
          }
          #styloaix-button.icon-colored {
            list-style-image: url('chrome://userchromejs/content/styloaix/16.png');
          }
          .styloaix-usersheet label:after {
            content:"US";
            color: blue;
          }
          .styloaix-agentsheet label:after {
            content:"AG";
            color: green;
          }
        }
      `)),
      type: _uc.sss.AUTHOR_SHEET
    },
 
    styles: new Map(),
 
    destroy: function () {
      xPref.unlock(this.PREF_MOZDOCUMENT);
      xPref.removeListener(this.prefListener);
      xPref.removeListener(this.prefListenerAll);
      CustomizableUI.destroyWidget('styloaix-button');
      _uc.sss.unregisterSheet(this.STYLE.url, this.STYLE.type);
      this.toggleAll({disable: true});
      delete UC.styloaix;
    }
  }
 
  class DisabledSet extends Set {
    constructor (iterable) {
      super(iterable);
    }
 
    add (item) {
      let cache_add = Set.prototype.add.call(this, item);
      xPref.set(UC.styloaix.PREF_STYLESDISABLED, JSON.stringify([...this]));
      return cache_add;
    }
 
    delete (item) {
      let cache_delete = Set.prototype.delete.call(this, item);
      xPref.set(UC.styloaix.PREF_STYLESDISABLED, JSON.stringify([...this]));
      return cache_delete;
    }
  }
 
  class UserStyle {
    constructor(file) {
      this.type = file.leafName.endsWith('us.css') ?
                    _uc.sss.USER_SHEET :
                  file.leafName.endsWith('as.css') ?
                    _uc.sss.AGENT_SHEET :
                    _uc.sss.AUTHOR_SHEET;
      this.file = file;
      this.fullName = file.leafName;
      this.name = file.leafName.replace(/(?:\.(?:user|as|us))?\.css$/, '');
      this.url = Services.io.newURI('resource://userchromejs/UserStyles/' + file.leafName);
      this.enabled = !UC.styloaix.disabledStyles.has(this.fullName);
      UC.styloaix.styles.set(this.fullName, this);
    }
    register () {
      _uc.sss.loadAndRegisterSheet(this.url, this.type);
    }
    unregister () {
      _uc.sss.unregisterSheet(this.url, this.type);
    }
    reload () {
      if (this.enabled)
        this.unregister();
      UC.styloaix.toggleStyle(this, {aStatus: true});
    }
    delete () {
      if (Services.prompt.confirm(null, 'StyloaiX', 'Delete "' + this.fullName + '" permanently?')) {
        UC.styloaix.styles.delete(this.fullName);
        if (this.enabled)
          this.unregister();
        else
          UC.styloaix.disabledStyles.delete(this.fullName);
        UC.styloaix.rebuildMenu();
        this.file.remove(false);
      }
    }
  }
 
  UC.styloaix.init();
 
})()
cambriancn
小狐狸
小狐狸
  • UID57310
  • 注册日期2019-10-10
  • 最后登录2022-10-05
  • 发帖数28
  • 经验30枚
  • 威望0点
  • 贡献值16点
  • 好评度1点
2楼#
发布于:2021-04-04 22:02
下载这个火狐配置好的包,里面有你要的,而且做了一些界面美化
https://561234.xyz/Accelerate/%E5%96%84%E7%94%A8%E4%BD%B3%E8%BD%AF/Firefox
逗妇乳
小狐狸
小狐狸
  • UID50148
  • 注册日期2015-06-01
  • 最后登录2022-11-21
  • 发帖数83
  • 经验89枚
  • 威望0点
  • 贡献值32点
  • 好评度6点
3楼#
发布于:2021-04-05 21:07
cambriancn:下载这个火狐配置好的包,里面有你要的,而且做了一些界面美化
https://561234.xyz/Accelerate/%E5%96%84%E7%94%A8%E4%BD%B3%E8%BD%AF/Firefox
回到原帖
这就是我分享的
逗妇乳
小狐狸
小狐狸
  • UID50148
  • 注册日期2015-06-01
  • 最后登录2022-11-21
  • 发帖数83
  • 经验89枚
  • 威望0点
  • 贡献值32点
  • 好评度6点
4楼#
发布于:2021-04-05 21:08
kidzgy:从别处淘来的脚本,可以试一下
// ==UserScript==
// @name            StyloaiX 用户样式管理
// @author          xiaoxiaoflood
// @include  ...
回到原帖
你淘到的就是我分享的版本
kidzgy
火狐狸
火狐狸
  • UID35190
  • 注册日期2011-02-03
  • 最后登录2023-01-31
  • 发帖数235
  • 经验181枚
  • 威望0点
  • 贡献值114点
  • 好评度16点
5楼#
发布于:2021-04-05 23:54
逗妇乳:你淘到的就是我分享的版本回到原帖
版本有些代码不一样哦,你可以试一下,来自于这里https://bbs.kafan.cn/thread-2205920-1-1.html,我还特别对比过,原作者的编辑是空白,而这个不会。
逗妇乳
小狐狸
小狐狸
  • UID50148
  • 注册日期2015-06-01
  • 最后登录2022-11-21
  • 发帖数83
  • 经验89枚
  • 威望0点
  • 贡献值32点
  • 好评度6点
6楼#
发布于:2021-04-06 10:33
kidzgy:版本有些代码不一样哦,你可以试一下,来自于这里https://bbs.kafan.cn/thread-2205920-1-1.html,我还特别对比过,原作者的编辑是空白,而这个不会。回到原帖
这就是我分享的配置
逗妇乳
小狐狸
小狐狸
  • UID50148
  • 注册日期2015-06-01
  • 最后登录2022-11-21
  • 发帖数83
  • 经验89枚
  • 威望0点
  • 贡献值32点
  • 好评度6点
7楼#
发布于:2021-04-06 10:33
kidzgy:版本有些代码不一样哦,你可以试一下,来自于这里https://bbs.kafan.cn/thread-2205920-1-1.html,我还特别对比过,原作者的编辑是空白,而这个不会。回到原帖
大叔逗妇乳就是我的卡饭账号
cambriancn
小狐狸
小狐狸
  • UID57310
  • 注册日期2019-10-10
  • 最后登录2022-10-05
  • 发帖数28
  • 经验30枚
  • 威望0点
  • 贡献值16点
  • 好评度1点
8楼#
发布于:2021-04-06 19:31
你试试 config.js 还有chrome下对应的文件夹 也拷贝过来
kidzgy
火狐狸
火狐狸
  • UID35190
  • 注册日期2011-02-03
  • 最后登录2023-01-31
  • 发帖数235
  • 经验181枚
  • 威望0点
  • 贡献值114点
  • 好评度16点
9楼#
发布于:2021-04-09 20:34
逗妇乳:这就是我分享的配置回到原帖
游客

返回顶部