Forest捣鼓日记

真是有意思。。就写插件的吧,Android 实在整不明白。

当前适用 5.2.1 版本。其他版本都大同小异,大部分可以通用,剩下的根据相似信息找找就行。

种所有树

法一:须登录(不推荐)

插件根目录下 background.js 中,替换

1
"/tree_types/unlocked"

1
"/tree_types"

并对 options.js 也进行这个操作。

法二:不用登录

background.js 中,替换

1
ia=[31,32,40,42,43,44,48,49,50,51,52,53,54,55,56,59,60,61,66,70,73,77,78]

1
ia=[]

popup.js 中,替换

1
s.isLocked

1
false

这个方法最省事啦!

种树秒出

插件根目录下 background.js 中,替换

1
Math.round((new Date(a.endTime).getTime()-Date.now())/1e3)>0

1
0

然后打开背景页的 DevTools,刷新即可。

只要不刷新都能正常使用,除非浏览器被清了后台,插件重新加载。

查看插件源代码

利用插件给出的 map 文件,写了一个小小的程序。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import json
import os

def mkdir(path):
if not os.path.exists(path):
os.makedirs(path)

def write(file):
base = 'C:/Users/HUAWEI/AppData/Local/Twinkstar/User Data/Default/Extensions/kjacjjdnoddnpbbcjilcajfhhbdhkpgk/5.2.1_0'
s = json.load(open(os.path.join(base, file + ".js.map"), "r", encoding = "utf-8"))
k, l = s["sources"], s["sourcesContent"]
for i, content in enumerate(l):
k[i] = "forest/" + k[i][3:]
p, f = os.path.split(k[i])
mkdir(p)
f = open(k[i], "w", encoding = "utf-8")
try:
f.write(content)
except:
continue

if __name__ == "__main__":
li = ["background", "options", "popup", "content"]
for i in li:
write(i)

也是谷歌码风好评。(虽然我已经好久不用二缩进了)

更改种树时间限制

上下限

1
l=600,u=7200

这俩是上下限。

调一下上限 180 分钟

1
l=600,u=10800

时间调整

搜这个:

1
i-300

这个 300 是每次调的秒数,就是 5 分钟。为了兼顾调整时间的速度与精细程度,我把每次减的时间变成 4 分钟。

1
i-240

个性化全页面倒计时

法一(不推荐)

需要把 popup 搞到一个新的标签页里面,可是费了一番功夫。

最后能找到的最好办法:在 background.js 里加一句话。

替换

1
(()=>{var Sn=Object.create;

1
(()=>{var Sn=Object.create;chrome.tabs.create({'url': chrome.extension.getURL('popup.html')});

这样每次启动插件的时候就会蹦出新标签页 popup.html

法二

eeee似乎也不用,直接打开网址就行了。chrome-extension://kjacjjdnoddnpbbcjilcajfhhbdhkpgk/popup.html

界面美化

popup.js 里。

背景居中

替换

1
2
3
4
* {
margin: 0;
user-select: none;
}

1
2
3
4
5
6
7
8
9
* {
margin: 0;
user-select: none;
}

#root {
display: flex;
justify-content: center;
}

背景全屏

替换

1
2
width: 295px;
height: 329px;

1
2
width: 96vw;
height: 96vh;

整体居中

替换

1
2
3
flex-direction: column;
align-items: center;
padding-top: 16px;

1
2
3
4
flex-direction: column;
justify-content: center;
align-items: center;
padding-top: 16px;

工具栏调整

替换

1
2
3
4
5
6
7
8
var qd=B.div`
height: 32px;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding-left: 6px;
padding-right: 6px;

1
2
3
4
5
6
7
8
var qd=B.div`
height: 32px;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
padding-left: 20vw;
padding-right: 20vw;

植物球

图片替换

用最高画质的植物球替换掉两个低画质的。plant-ball-3IVJV4LF.pngplant-ball-IEGHSBP6.png

用最高画质的地面换掉低画质的。

用最高画质的树换掉低画质的:

另外加入主题系统,可选换主题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import json
import re
import os

def move(src, dst):
if os.path.exists(dst):
os.system('xcopy "{}" "{}" /Y/Q'.format(src, dst))
else:
os.system('echo f | xcopy "{}" "{}" /Q'.format(src, dst))

if __name__ == "__main__":
default, christmas, birthday, tinytan = 0, 1, 2, 3
theme = tinytan

root = "D:\\phpstudy\\azhe\\forest\\"
root1 = "C:\\Users\\HUAWEI\\AppData\\Local\\Twinkstar\\User Data\\Default\\Extensions\\kjacjjdnoddnpbbcjilcajfhhbdhkpgk\\5.2.1_0\\"
data = json.load(open(root + "treeType.json", "r", encoding = "utf-8"))
treeCnt = len(data)
treeJson = ""

base = root + "trees\\"
base1 = root1 + "images\\plants\\"
for i in data:
gid = int(i)
print(gid)
phases = data[i]["phase"]["growth"]
hasChristmas = data[i]["phase"]["hasChristmas"]
if hasChristmas:
phasesXmas = data[i]["phase"]["christmas"]
name = data[i]["nameFile"]
for phase in phases:
if theme == christmas and hasChristmas and phase in phasesXmas:
src = base + name + "_phase_{}_christmas.png".format(phase)
else:
src = base + name + "_phase_{}.png".format(phase)
dst = base1 + i + "\\" + str(phase) + ".png"
move(src, dst)
if data[i]["phase"]["hasDead"]:
src = base + name + "_phase_dead.png"
dst = base1 + i + "\\dead.png"
move(src, dst)
treeJson += "{id:" + i + ',phaseType:"'
treeJson += "Seven" if len(phases) == 7 else "Four"
treeJson += '",name:"' + data[i]["nameEN"] + '",images:{'
for p in phases:
treeJson += '"{p}":"./images/plants/{i}/{p}.png"'.format(p = p, i = gid)
if p != phases[-1] or data[i]["phase"]["hasDead"]:
treeJson += ","
if data[i]["phase"]["hasDead"]:
treeJson += 'dead:"./images/plants/{}/dead.png"'.format(gid)
treeJson += "}}"
if gid != treeCnt - 1:
treeJson += ","

for file in ["background.js", "options.js"]:
treeStr = open(root1 + file, "r", encoding = "utf-8").read()
s = re.findall(r"(?<=\[)\{.*?\}\}(?=\])", treeStr)
treeStr = treeStr.replace(s[0], treeJson)
open(root1 + file, "w", encoding = "utf-8").write(treeStr)

print("plant ball")
src = root + "background\\plant_ball.png"
if theme == christmas:
src = root + "background\\plant_ball_christmas.png"
elif theme == birthday:
src = root + "background\\plant_ball_hbd.png"
elif theme == tinytan:
src = root + "background\\tinytan_plant_ball.png"
ballList = ["plant-ball-3IVJV4LF.png", "plant-ball-IEGHSBP6.png"]
for ball in ballList:
move(src, root1 + ball)

print("earth")
src = root + "background\\ground_piece.png"
if theme == christmas:
src = root + "background\\ground_piece_xmas.png"
elif theme == tinytan:
src = root + "background\\tinytan_ground_piece.png"
dst = root1 + "ground-piece-LLMV3YMI.png"
move(src, dst)

src = root + "background\\ground_left_side.png"
if theme == christmas:
src = root + "background\\left_xmas.png"
elif theme == tinytan:
src = root + "background\\tinytan_ground_left_side.png"
dst = root1 + "ground-left-YH3VQTLM.png"
move(src, dst)

src = root + "background\\ground_right_side.png"
if theme == christmas:
src = root + "background\\right_xmas.png"
elif theme == tinytan:
src = root + "background\\tinytan_ground_right_side.png"
dst = root1 + "ground-right-63ETKNDR.png"
move(src, dst)

直接连不能种的树也放在里面。还得先登记一下。

放大一些

替换

1
2
3
4
5
6
7
8
9
10
11
height: 120px;
width: 120px;
display: flex;
justify-content: center;
align-items: center;
cursor: ${({isLocked:e})=>e?"not-allowed":"pointer"};
position: relative;
`,of=B.img.attrs({draggable:!1})`
width: 72px;
height: 72px;
margin-top: -25px;

1
2
3
4
5
6
7
8
9
10
11
12
background-size: 100%;
height: 45vh;
width: 45vh;
display: flex;
justify-content: center;
align-items: center;
cursor: ${({isLocked:e})=>e?"not-allowed":"pointer"};
position: relative;
`,of=B.img.attrs({draggable:!1})`
width: 27vh;
height: 27vh;
margin-top: -10vh;

时间显示框

替换

1
2
3
4
5
margin-top: 8px;
display: flex;
justify-content: center;
align-items: center;
transform: scale(1);

1
2
3
4
5
margin-top: 1vh;
display: flex;
justify-content: center;
align-items: center;
transform: scale(1);

时间本身

替换

1
2
3
4
5
6
7
font-size: 50px;
font-weight: 500;
width: 162px;
height: 70px;
line-height: 70px;
text-align: center;
transform: scale(1);

1
2
3
4
5
6
7
font-size: 18vh;
font-weight: 500;
width: 50vh;
height: 20vh;
line-height: 20vh;
text-align: center;
transform: scale(1);

减少无用信息

减字(不推荐)

_locales\zh_CN\messages.json

替换

1
2
3
"extension_blacklist_mode": {
"message": "封锁名单模式"
},

1
2
3
"extension_blacklist_mode": {
"message": "BLACK"
},

替换

1
2
3
"extension_whitelist_mode": {
"message": "允许名单模式"
},

1
2
3
"extension_whitelist_mode": {
"message": "WHITE"
},

去掉切换模式按钮

popup.js 中,

替换

1
2
3
4
5
6
7
8
color: #fff;
font-size: 14px;
padding-left: 12px;
padding-right: 12px;
position: relative;
display: grid;
place-items: center;
cursor: pointer;

1
2
3
4
5
6
7
8
color: #fff;
font-size: 14px;
padding-left: 12px;
padding-right: 12px;
position: relative;
display: none;
place-items: center;
cursor: pointer;

去掉鼓励的话

替换

1
2
3
4
5
6
7
8
display: grid;
place-items: center;
height: 42px;
line-height: 22px;
font-size: 16px;
margin-top: 11px;
padding: 0 24px;
text-align: center;

1
2
3
4
5
6
7
8
display: none;
place-items: center;
height: 42px;
line-height: 22px;
font-size: 16px;
margin-top: 11px;
padding: 0 24px;
text-align: center;

去掉加入白名单(黑名单)快捷键

感觉是最难的一个,CSS修改不好使,只好在生成元素的时候动手脚。

替换

1
{return r==="Idle"?A===null?w0.default.createElement(SA,null):w0.default.createElement(EA,{isSiteInList:A,addSiteToList:m,siteBlockingMode:i}):w0.default.createElement(SA,null)}

1
{return w0.default.createElement(SA,null)}

修复标签显示异常问题

这个也不简单,但也挺简单的 /cy。

background.js 中,

替换

1
{let{data:a}=await G.default.get("/tags");return(0,fa.default)(a.tags,{deep:!0})}

1
{let{data:a}=await G.default.get("/tags");var b=[];for(var i=0;i<a.tags.length;++i){if(a.tags[i].deleted===false)b.push(a.tags[i]);}return(0,fa.default)(b,{deep:!0})}

options.js 中,

替换

1
{let{data:e}=await Sn.default.get("/tags");return(0,ia.default)(e.tags,{deep:!0})}

1
{let{data:e}=await Sn.default.get("/tags");var b=[];for(var i=0;i<e.tags.length;++i){if(e.tags[i].deleted===false)b.push(e.tags[i]);}return(0,ia.default)(b,{deep:!0})}

修复服务器瞎改标签和批注的毛病

发现只有在新创造一棵树的时候会出现这个问题,于是采用加一次 PUT 来弥补。

options.js 里,

替换

1
let y=await Ff(x.plant);return{...x,plant:y,syncStatus:"Succeeded"}

1
let createdPlant=await Ff(x.plant);createdPlant.tag=x.plant.tag;createdPlant.note=x.plant.note;let y=await Vf(createdPlant);return{...x,plant:y,syncStatus:"Succeeded"}

在同步一棵树和一起同步的时候都有这段代码

替换

1
let c=await Ff(t.plant);return{...u,plant:c,syncStatus:"Succeeded"}

1
let createdPlant=await Ff(t.plant);createdPlant.tag=t.plant.tag;createdPlant.note=t.plant.note;let c=await Vf(createdPlant);return{...u,plant:c,syncStatus:"Succeeded"}

好难。

  • Copyrights © 2020-2023 STDquantum