整個故事是這樣的:我討厭 Chrome 的白色背景,當我打開新標籤或點擊連結時,螢幕會變白,灼傷我的眼睛。 Stylebot 擴充似乎不允許在新分頁或載入白色螢幕中更改顏色。
當我在 Firefox 上安裝完整的深色主題(那些舊主題)時,Firefox 就沒有這個問題。所以現在我想放棄 Chrome 並開始使用 Firefox。但眾所周知,Stylebot 沒有 Firefox 版本。
我還沒有找到一個像 Firefox 的 Stylebot 一樣好的插件,而且那些接近 Stylebot 的插件都是有缺陷的,並且會把網站弄亂。
所以我考慮在 Chrome 的 Stylebot 中採用我的預設並將其匯出為 Stylish 擴充樣式。我不知道這是否可能,而且我真的對任何類型的編碼一無所知。如果這能以某種方式起作用,那將是金色的!
我放棄了嘗試改變Chrome的白色背景,因為太麻煩了。一些更改適用於白色加載螢幕,但不適用於新標籤頁。即使將新選項卡更改為任何其他 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 並以 Stylish 格式為其產生 css 應該是非常簡單的。實際上,我有時會解決這個問題,如果我能解決這個問題,我會發布我的東西。
答案2
警告:
在將轉換後的json匯入stylish/stylus之前,請務必先備份您現有的設定。我只在導出的設定上驗證了它,它可能包含錯誤!
我剛剛編寫了一個腳本將 stylebot json 轉換為 vintage/stylus json。
要使用該腳本,您需要安裝 Python 3。假設您已將腳本下載為s2s.py
,請使用下列命令執行腳本:
python3 s2s.py stylebot.json -o stylus.json -e utf-8
-o
和參數-e
是可選的。
我知道這是一種醜陋的程式碼,但誰在乎呢: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)