3

The whole story is this: I hate Chrome's white background and when I open a new tab or click on a link, the screen goes white, burning my eyes up. Stylebot extension doesn't seem to be allowed to change colors in new tab or in loading white screens.

Firefox doesn't have that problem when I install complete dark themes on it (those old themes). So now I want to leave Chrome behind and start using Firefox. But as we all know, Stylebot doesn't have a Firefox version.

I haven't found an addon as good as Stylebot for Firefox and the ones that get close to Stylebot are buggy and messes the websites up.

So I thought about taking my presets in Chrome's Stylebot and export it to a Stylish extension style. I don't know if that's possible and I really don't know anything about any type of coding. If that works somehow, it would be golden!

I gave up on trying to change Chrome's white background because it was too troublesome. Some changes worked for the white loading screen, but not for the new tab page. Even extensions that change the new tab to any other URL didn't worked. It always shows the white screen before finishing loading.

So... can anyone help me out?

2 Answers 2

0

I'm looking into this myself. So Stylish exports/imports with the following format - this includes two examples from userstyles.org and one I made very quickly:

[
  {
    "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 lets one backup and export their styles in this JSON format:

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

It should be pretty trivial to write some code to loop through Stylebot's returned JSON and generate the css for it in the Stylish format. I'm actually going to tackle this sometime and will post my stuff if I ever get to it.

0

CAUTION:

Before importing the converted json to stylish/stylus, be sure to backup your existing settings first. I have only verified it on my exported settings and it may contain bugs!


I just wrote a script to convert stylebot json to stylish/stylus json.

To use the script you need to have Python 3 installed. Assuming you have downloaded the script as s2s.py, run the script with:

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

The -o and -e arguments are optional.

GitHub Gist

I know it's kind of ugly code but who cares :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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .