Chrome에서 Stylebot 스타일을 Stylish 형식으로 내보내는 방법이 있나요?

Chrome에서 Stylebot 스타일을 Stylish 형식으로 내보내는 방법이 있나요?

전체적인 이야기는 이렇습니다. 저는 Chrome의 흰색 배경이 싫고, 새 탭을 열거나 링크를 클릭하면 화면이 하얗게 변해 눈이 따가워집니다. Stylebot 확장 프로그램은 새 탭이나 흰색 화면 로딩 시 색상을 변경할 수 없는 것 같습니다.

Firefox에 완전한 어두운 테마(이전 테마)를 설치하면 그런 문제가 발생하지 않습니다. 이제 저는 Chrome을 뒤로하고 Firefox를 사용하고 싶습니다. 그러나 우리 모두 알고 있듯이 Stylebot에는 Firefox 버전이 없습니다.

저는 Firefox용 Stylebot만큼 좋은 애드온을 찾지 못했고, Stylebot에 가까운 애드온은 버그가 있고 웹사이트를 엉망으로 만듭니다.

그래서 Chrome의 Stylebot에서 사전 설정을 가져와 Stylish 확장 스타일로 내보내는 것을 고려했습니다. 그것이 가능한지 모르겠고 어떤 유형의 코딩에 대해서도 전혀 모릅니다. 그것이 어떻게든 작동한다면, 그것은 황금이 될 것입니다!

크롬 흰색 배경을 바꾸려는 건 너무 귀찮아서 포기했어요. 일부 변경 사항은 흰색 로딩 화면에서는 작동했지만 새 탭 페이지에서는 작동하지 않았습니다. 새 탭을 다른 URL로 변경하는 확장 프로그램도 작동하지 않았습니다. 로딩이 완료되기 전에 항상 흰색 화면이 표시됩니다.

그럼... 누구든지 나를 도와줄 수 있나요?

답변1

나는 이것을 직접 조사하고 있습니다. 따라서 다음 형식의 세련된 내보내기/가져오기 - 여기에는 userstyles.org의 두 가지 예와 제가 매우 빠르게 만든 예가 포함되어 있습니다.

[
  {
    "sections": [
      {
        "urls": [],
        "urlPrefixes": [],
        "domains": [
          "myjetbrains.com"
        ],
        "regexps": [],
        "code": "body.global { /*etc */}"
      }
    ],
    "url": "http://userstyles.org/styles/133921",
    "updateUrl": "https://userstyles.org/styles/chrome/133921.json",
    "md5Url": "https://update.userstyles.org/133921.md5",
    "originalMd5": "7963f3cfdce94512ebd74a0098a56b38",
    "name": "YouTrack Dark TV Style",
    "method": "saveStyle",
    "enabled": true,
    "id": 1
  },
  {
    "sections": [
      {
        "urls": [],
        "urlPrefixes": [],
        "domains": [],
        "regexps": [],
        "code": "/* 4chan - Midnight Caek */\r\n@namespace url(http://www.w3.org/1999/xhtml);"
      },
      {
        "urls": [],
        "urlPrefixes": [],
        "domains": [
          "4chan.org"
        ],
        "regexps": [],
        "code": "/* hides Captcha table row */\r\n\r\n/* body background and text color */\r\nhtml, body { /*etc */}"
      },
      {
        "urls": [],
        "urlPrefixes": [],
        "domains": [
          "dis.4chan.org"
        ],
        "regexps": [],
        "code": "body { /*etc */}"
      }
    ],
    "url": "http://userstyles.org/styles/65821",
    "updateUrl": "https://userstyles.org/styles/chrome/65821.json?ik-passtoggle=ik-No",
    "md5Url": "https://update.userstyles.org/65821.md5",
    "originalMd5": "d34520a7525de8e0c174d466697c50db",
    "name": "4chan - Midnight Caek",
    "method": "saveStyle",
    "enabled": true,
    "id": 2
  },
  {
    "method": "saveStyle",
    "name": "stackoverflow improvement",
    "enabled": true,
    "sections": [
      {
        "urls": [],
        "urlPrefixes": [],
        "domains": [
          "superuser.com"
        ],
        "regexps": [],
        "code": "body{background:#ddd;}\n"
      }
    ],
    "updateUrl": null,
    "md5Url": null,
    "url": null,
    "originalMd5": null,
    "id": 3
  }
]

Stylebot을 사용하면 스타일을 다음 JSON 형식으로 백업하고 내보낼 수 있습니다.

{
  "abcnews.go.com":{
    "_enabled":true,
    "_rules":{
      "div.t_callout":{
        "display":"none"
      }
    }
  },
  "boingboing.net":{
    "_enabled":true,
    "_rules":{
      "#next-post-thumbnails":{
        "display":"none"
      }
    }
  }
}

Stylebot이 반환한 JSON을 반복하고 이에 대한 CSS를 Stylish 형식으로 생성하는 코드를 작성하는 것은 매우 간단합니다. 나는 실제로 이 문제를 언젠가 다룰 예정이며, 기회가 된다면 내 자료를 게시할 것입니다.

답변2

주의:

변환된 json을 스타일리시/스타일러스로 가져오기 전에 먼저 기존 설정을 백업하세요. 내보낸 설정에서만 확인했으며 버그가 있을 수 있습니다!


방금 stylebot json을 Stylish/stylus json으로 변환하는 스크립트를 작성했습니다.

스크립트를 사용하려면 Python 3이 설치되어 있어야 합니다. 스크립트를 로 다운로드했다고 가정하고 다음을 s2s.py사용하여 스크립트를 실행합니다.

python3 s2s.py stylebot.json -o stylus.json -e utf-8

및 인수 -o-e선택 사항입니다.

GitHub 요지

나는 그것이 일종의 추악한 코드라는 것을 알고 있지만 누가 신경 쓰나요 :P

import argparse
import json


def stylebot_to_stylus(source='sb.json', target='stylus.json', encoding='utf-8'):

    with open(source, encoding=encoding) as f:
        data = json.load(f)

    result_list = []
    item_id = 1
    for domain_name in data:
        item_dict = {}
        item_dict["id"] = item_id
        item_id += 1
        item_dict["enabled"] = data[domain_name]['_enabled']
        item_dict["name"] = domain_name

        # only one section for each domain (group)
        sections = []
        section0 = {}
        section0['urls'] = []
        section0['domains'] = []

        # add the domain or the group of domains
        if ',' in domain_name:
            for addr in domain_name.split(sep=','):
                section0['domains'].append(addr.strip())
        else:
            section0['domains'].append(domain_name)

        css_rule = ''

        # construct a css rule for each domain (group)
        for selector in data[domain_name]['_rules']:
            css_rule += selector + '{'
            for attr in data[domain_name]['_rules'][selector]:
                css_rule += attr + ':'
                css_rule += data[domain_name]['_rules'][selector][attr] + ';'
            css_rule += '}'
        section0['code'] = css_rule

        sections.append(section0)
        item_dict['sections'] = sections

        result_list.append(item_dict)

    with open(target, "w", encoding=encoding) as of:
        of.write(json.dumps(result_list))


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("source",
                        help="input json file, exported from Stylebot[Lite]")
    parser.add_argument('-o', '--output',
                        help='output json file, can be imported to Stylus')
    parser.add_argument('-e', '--encoding',
                        help='output json file, can be imported to Stylus')

    args = parser.parse_args()
    src = args.source
    out = args.output if args.output else 'stylus_output.json'
    enc = args.encoding if args.encoding else 'utf-8'

    stylebot_to_stylus(src, out, enc)

관련 정보