使用tBodies方法

1
2
var table = document.getElementById('cal_panel');
var tbody = table.tBodies[0];

推荐使用这种方式.

通过tbody上的id属性

1
2
3
<tbody id='cal_panel_body'>
......
</tbody>

然后通过:

1
var tbody = document.getElementById('cal_panel_body');

来获取.

参考资料

https://bbs.csdn.net/topics/360143208

百度翻译音频的下载链接格式

1
https://fanyi.baidu.com/gettts?lan=en&text=单词&spd=5&source=web

其中spd表示速度,数值越大朗读越快.

示例

1
2
3
4
5
6
7
8
9
10
点击播放(omega):<i class="fa fa-play" aria-hidden="true" onclick="play('audioID5JswJWS3')"></i>

<audio src="https://fanyi.baidu.com/gettts?lan=en&text=omega&spd=5&source=web" id="audioID5JswJWS3"></audio>
<script>
function play(id){
if(id!=null){
var audio=document.getElementById(id);audio.play();
}
}
</script>

点击播放(omega):

升级

为了使用方便,我封装成如下JS方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function sst(text) {
// 创建<audio></audio>元素
var audio = document.createElement("audio");
// 设置音频地址
audio.src = "https://fanyi.baidu.com/gettts?lan=en&text=" + text + "&spd=5&source=web";
// audio.src = "https://fanyi.baidu.com/gettts?lan=en&text=omega&spd=5&source=web";
// 添加到body元素中
document.body.appendChild(audio);
console.log(audio.src);
audio.loop = false;
// 播放
audio.play();
// 监听播放结束
audio.addEventListener('ended', function () {
// alert('play ended');
// 从body元素中移除掉,以便下次使用
document.body.removeChild(audio);
}, false);
}

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<button onclick="sst('omega')">omega</button><button onclick="sst('audio')">audio</button>
<script>
function sst(text) {
// 创建<audio></audio>元素
var audio = document.createElement("audio");
// 设置音频地址
audio.src = "https://fanyi.baidu.com/gettts?lan=en&text=" + text + "&spd=5&source=web";
// audio.src = "https://fanyi.baidu.com/gettts?lan=en&text=omega&spd=5&source=web";
// 添加到body元素中
document.body.appendChild(audio);
// console.log(audio.src);
audio.loop = false;
// 播放
audio.play();
// 监听播放结束
audio.addEventListener('ended', function () {
// alert('play ended');
// 从body元素中移除掉,以便下次使用
document.body.removeChild(audio);
}, false);
}
</script>

直接document.write

1
2
3
<script language="javascript">
document.write("<script src='test.js'><\/script>");
</script>

动态改变已有script的src属性

1
2
3
4
5
<script src='' id="s1"></script>
<script language="javascript">
var scriptE=document.getElementById("s1");
scriptE.src="test.js"
</script>

动态创建script元素

1
2
3
4
5
6
7
<script>
var headDom = document.getElementsByTagName('HEAD').item(0);
var scriptDom= document.createElement("script");
scriptDom.type = "text/javascript";
scriptDom.src="test.js";
headDom.appendChild(scriptDom);
</script>

使用jQuery

使用getScript(url,callback)方法实现动态加载js文件

1
2
3
$.getScript('test.js',function(){
alert('done');
});

参考资料

https://www.jb51.net/article/17992.htm
https://www.jb51.net/article/139481.htm

问题描述

这是是hexo默认的markdown引擎与mathjax冲突造成的.

1
2
3
4
5
6
7
8
9
10
11
$$
\require{cancel}
\begin{array}{rl}
\verb|y+\cancel{x}| & y+\cancel{x}\\
\verb|\cancel{y+x}| & \cancel{y+x}\\
\verb|y+\bcancel{x}| & y+\bcancel{x}\\
\verb|y+\xcancel{x}| & y+\xcancel{x}\\
\verb|y+\cancelto{0}{x}| & y+\cancelto{0}{x}\\
\verb+\frac{1\cancel9}{\cancel95} = \frac15+& \frac{1\cancel9}{\cancel95} = \frac15 \\
\end{array}
$$

解决方案1 更换引擎

卸载原来的hexo引擎:

1
npm uninstall --save hexo-renderer-marked

使用另一个hexo引擎

1
npm install --save hexo-renderer-kramed

还需要注意的是使用\\只在多行公式内有效:
也就是要写成如下形式:

1
2
3
4
5
6
$$
\begin{align}
a &=1 & b &=2 & c &=3 \\
d &=-1 & e &=-2 & f &=-5
\end{align}
$$

显示效果:

$$
\begin{align}
a &=1 & b &=2 & c &=3 \
d &=-1 & e &=-2 & f &=-5
\end{align}
$$

行内公式是不换行的:

1
2
3
4
5
6
测试:$
\begin{align}
a &=1 & b &=2 & c &=3 \\
d &=-1 & e &=-2 & f &=-5
\end{align}
$

测试:$
\begin{align}
a &=1 & b &=2 & c &=3 \
d &=-1 & e &=-2 & f &=-5
\end{align}
$

解决方案2 使用四个反引号

也可以不卸载hexo-renderer-marked,在使用四个反引号替代LaTex的两个反引号。

  • \\\\替代原来的\\
  • \_替代原来的_,
  • \*替代原来的*
1
2
3
4
5
6
$$
\begin{aligned}
a &=1 & b &=2 & c &=3 \\\\
d &=-1 & e &=-2 & f &=-5
\end{aligned}
$$

显示效果:

$$
\begin{aligned}
a &=1 & b &=2 & c &=3 \\
d &=-1 & e &=-2 & f &=-5
\end{aligned}
$$

参考资料

https://segmentfault.com/a/1190000007261752

问题描述

今天我在电脑上写好博客后,使用如下命令推送到远程仓库中。

1
git push origin src

等到我睡觉前,想在手机上继续写点东西,写好后我提交,这都没问题,但是当我推送到远程的时候,出错了,说我不能提交,所以我使用如下命令先拉取远程仓库:

1
git pull origin src

想着解决一下冲突,再提交,但经过排查,好像冲突的是二进制文件 我也不好修改。

解决方案

所幸的是,手机上修改的并不多,所以我可以回退手机上的版本,丢弃手机上的修改:

1
git reset --hard HEAD^

然后再拉取远程仓库:

1
git pull origin src

这样就可以了

git rebase的作用

当你完成比较复杂的一个任务的时候,你可能提交了多次commit,经过一系列的commit后,你最终完成了任务,然后你想推送到远程仓库中.
但是如果你此时直接push到远程仓库中,这样远程仓库中就有了好多冗余的commit,所以在push到远程仓库之前,应该将这些中间的commit合并成一个commit,然后再推送到远程仓库上,这样你的的commit记录就比较简洁清爽.

注意

不要通过rebase对任何已经提交到公共仓库中的commit进行修改(除非是你)
还有就是使用rebase的过程中不要在更改本地仓库中的任何内容,以免需要再次合并,或者再次提交.

压缩多个commit为一个新的commit

要合并commit的话,前提是要有多个commit,如果只是超前一个commit的话,直接push就行了,不需要合并

先查看commit历史

1
git log -10 --pretty=oneline
1
2
3
4
5
6
7
8
9
10
11
12
lan@DESKTOP-8ISAT6B MINGW64 /e/Blog/blog (master)
$ git log -10 --pretty=oneline
dce93fd66d8c01b3bb7e944ae43fe0165e5ae802 (HEAD -> master) 更新文章
1fcec380bdfe807de6ef6a36495683a5488b9f56 更新文章
b82a12ccc05de8d2e9ff162bf206b525e386d7fd 更新文章
92bf7d32990a43ca242e3b0a40b2e0f199ad1dd2 (origin/master, origin/HEAD) 更新 source/_posts/Git/git rebase命令.md
4cb6b92e18a0f9a1ce1d129523b6fe4ddfaac231 Merge branch 'master' of github.com:lanlan2017/blog into HEAD
4cc82482180152616e8cee8a6de919c7eb881053 删除文章中的无效图片,添加新的Git相关的文章,压缩commit
7dccad9a4db12c9a91c25b77ee941cc59e826614 压缩
1a31038c8c3b78e6675489d1af147d9ac2425d72 删除文章中的无效图片,添加新的Git相关的文章
bf682016607be6eabf1952ee9a2ca70c804442aa 添加新的Git相关的文章
9e845cfda2fa63dd4bb7f143a33a53c3308bccf7 删除文章中的无效图片

可以看到现在超前了3个commit,这3个commit其实做的是同一件事情,应该压缩成一个分支.

合并当前到远程之间的commit

先获取远程commit记录上的commit_id:

1
92bf7d32990a43ca242e3b0a40b2e0f199ad1dd2

然后输入如下命令,进行压缩:

1
git rebase -i 92bf7d32990a43ca242e3b0a40b2e0f199ad1dd2

保留第一个pick 后面的pick改为squash

记下来,会在vim中弹出如下内容:

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
pick b82a12c 更新文章
pick 1fcec38 更新文章
pick dce93fd 更新文章

&#35; Rebase 92bf7d3..dce93fd onto 92bf7d3 (3 commands)
&#35;
&#35; Commands:
&#35; p, pick &lt;commit&gt; = use commit
&#35; r, reword &lt;commit&gt; = use commit, but edit the commit message
&#35; e, edit &lt;commit&gt; = use commit, but stop for amending
&#35; s, squash &lt;commit&gt; = use commit, but meld into previous commit
&#35; f, fixup &lt;commit&gt; = like "squash", but discard this commit's log message
&#35; x, exec &lt;command&gt; = run command (the rest of the line) using shell
&#35; b, break = stop here (continue rebase later with 'git rebase --continue')
&#35; d, drop &lt;commit&gt; = remove commit
&#35; l, label &lt;label&gt; = label current HEAD with a name
&#35; t, reset &lt;label&gt; = reset HEAD to a label
&#35; m, merge [-C &lt;commit&gt; | -c &lt;commit&gt;] &lt;label&gt; [&#35; &lt;oneline&gt;]
&#35; . create a merge commit using the original merge commit's
&#35; . message (or the oneline, if no original merge commit was
&#35; . specified). Use -c &lt;commit&gt; to reword the commit message.
&#35;
E:/Blog/blog/.git/rebase-merge/git-rebase-todo [unix] (13:12 09/12/2019)2,1 顶端
"E:/Blog/blog/.git/rebase-merge/git-rebase-todo" [unix] 29L, 1214C

我们要修改其中的内容:按下i,进入vim插入模式,将第一个pick保留,后面的pick全部改成s:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pick b82a12c 更新文章
s 1fcec38 更新文章
s dce93fd 更新文章

&#35; Rebase 92bf7d3..dce93fd onto 92bf7d3 (3 commands)
&#35;
&#35; Commands:
&#35; p, pick &lt;commit&gt; = use commit
&#35; r, reword &lt;commit&gt; = use commit, but edit the commit message
&#35; e, edit &lt;commit&gt; = use commit, but stop for amending
&#35; s, squash &lt;commit&gt; = use commit, but meld into previous commit
&#35; f, fixup &lt;commit&gt; = like "squash", but discard this commit's log message
&#35; x, exec &lt;command&gt; = run command (the rest of the line) using shell
&#35; b, break = stop here (continue rebase later with 'git rebase --continue')
&#35; d, drop &lt;commit&gt; = remove commit
&#35; l, label &lt;label&gt; = label current HEAD with a name
&#35; t, reset &lt;label&gt; = reset HEAD to a label
&#35; m, merge [-C &lt;commit&gt; | -c &lt;commit&gt;] &lt;label&gt; [&#35; &lt;oneline&gt;]
&#35; . create a merge commit using the original merge commit's
&#35; . message (or the oneline, if no original merge commit was
&#35; . specified). Use -c &lt;commit&gt; to reword the commit message.
&#35;

修改好了之后,按下ESC,然后输入:wq进行保存,这样会将上面的三个commit压缩到一个新的分支上.

写上新的commit的描述

然后还会在vim中弹出如下内容,让你写上压缩得到的新的分支的描述信息.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# This is a combination of 3 commits.
# This is the 1st commit message:

更新文章

# This is the commit message #2:

更新文章

# This is the commit message #3:

更新文章

&#35; Please enter the commit message for your changes. Lines starting
&#35; with '&#35;' will be ignored, and an empty message aborts the commit.
&#35;
&#35; Date: Mon Dec 9 13:08:03 2019 +0800
&#35;
&#35; interactive rebase in progress; onto 92bf7d3
&#35; Last commands done (3 commands done):
&#35; squash 1fcec38 更新文章
&#35; squash dce93fd 更新文章

这个地方按你的实际情况书写即可,为了演示方便,我改成如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# This is a combination of 3 commits.
# This is the 1st commit message:

更新文章_压缩得到的新的commit的描述信息

# This is the commit message #2:

更新文章_之前的commit描述1

# This is the commit message #3:

更新文章_之前的commit描述2

&#35; Please enter the commit message for your changes. Lines starting
&#35; with '&#35;' will be ignored, and an empty message aborts the commit.
&#35;
&#35; Date: Mon Dec 9 13:08:03 2019 +0800
&#35;
&#35; interactive rebase in progress; onto 92bf7d3
&#35; Last commands done (3 commands done):
&#35; squash 1fcec38 更新文章
&#35; squash dce93fd 更新文章

然后再次保存退出即可.

压缩效果

这样就压缩好了,压缩得到的分支如下:

1
2
3
4
5
6
7
8
9
10
11
12
lan@DESKTOP-8ISAT6B MINGW64 /e/Blog/blog (master)
$ git log -10 --pretty=oneline
226d81dfa724d963ca387f40505df4cf11fd42c7 (HEAD -> master) 更新文章_压缩得到的新的commit的描述信息
92bf7d32990a43ca242e3b0a40b2e0f199ad1dd2 (origin/master, origin/HEAD) 更新 source/_posts/Git/git rebase命令.md
4cb6b92e18a0f9a1ce1d129523b6fe4ddfaac231 Merge branch 'master' of github.com:lanlan2017/blog into HEAD
4cc82482180152616e8cee8a6de919c7eb881053 删除文章中的无效图片,添加新的Git相关的文章,压缩commit
7dccad9a4db12c9a91c25b77ee941cc59e826614 压缩
1a31038c8c3b78e6675489d1af147d9ac2425d72 删除文章中的无效图片,添加新的Git相关的文章
bf682016607be6eabf1952ee9a2ca70c804442aa 添加新的Git相关的文章
9e845cfda2fa63dd4bb7f143a33a53c3308bccf7 删除文章中的无效图片
b9ab7facc769e575b28fefd74e2154fd16087e52 添加新的Git相关的文章
29a6e2b0240c71240146f9a19029d8736055eb5b 添加JS相关文章,更新Git相关文章

可以看到:

1
2
3
dce93fd66d8c01b3bb7e944ae43fe0165e5ae802 (HEAD -> master) 更新文章
1fcec380bdfe807de6ef6a36495683a5488b9f56 更新文章
b82a12ccc05de8d2e9ff162bf206b525e386d7fd 更新文章

这三条commit都压缩成一个新的commit:

1
226d81dfa724d963ca387f40505df4cf11fd42c7 (HEAD -> master) 更新文章_压缩得到的新的commit的描述信息

再次修改commit描述

上面的commit描述,只是为了说明效果,可以输入如下命令,修改commit的内容:

1
git commit --amend
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
更新文章_压缩得到的新的commit的描述信息

更新文章_之前的commit描述1

更新文章_之前的commit描述2

&#35; Please enter the commit message for your changes. Lines starting
&#35; with '&#35;' will be ignored, and an empty message aborts the commit.
&#35;
&#35; Date: Mon Dec 9 13:08:03 2019 +0800
&#35;
&#35; On branch master
&#35; Your branch is ahead of 'origin/master' by 1 commit.
&#35; (use "git push" to publish your local commits)
&#35;
&#35; Changes to be committed:
&#35; modified: source/_posts/Git/git rebase命令.md
&#35;

修改为如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
更新文章_压缩得到的新的commit的描述信息

更新文章_之前的commit描述1

更新文章_之前的commit描述2

&#35; Please enter the commit message for your changes. Lines starting
&#35; with '&#35;' will be ignored, and an empty message aborts the commit.
&#35;
&#35; Date: Mon Dec 9 13:08:03 2019 +0800
&#35;
&#35; On branch master
&#35; Your branch is ahead of 'origin/master' by 1 commit.
&#35; (use "git push" to publish your local commits)
&#35;
&#35; Changes to be committed:
&#35; modified: source/_posts/Git/git rebase命令.md
&#35;
1
2
3
4
5
6
7
8
9
10
11
12
13
更新文章
&#35; Please enter the commit message for your changes. Lines starting
&#35; with '&#35;' will be ignored, and an empty message aborts the commit.
&#35;
&#35; Date: Mon Dec 9 13:08:03 2019 +0800
&#35;
&#35; On branch master
&#35; Your branch is ahead of 'origin/master' by 1 commit.
&#35; (use "git push" to publish your local commits)
&#35;
&#35; Changes to be committed:
&#35; modified: source/_posts/Git/git rebase命令.md
&#35;

效果

1
2
3
4
5
6
7
8
9
10
11
12
lan@DESKTOP-8ISAT6B MINGW64 /e/Blog/blog (master)
$ git log -10 --pretty=oneline
116161db01c2a19558da0c5b9360c979c46f1205 (HEAD -> master) 更新文章
92bf7d32990a43ca242e3b0a40b2e0f199ad1dd2 (origin/master, origin/HEAD) 更新 source/_posts/Git/git rebase命令.md
4cb6b92e18a0f9a1ce1d129523b6fe4ddfaac231 Merge branch 'master' of github.com:lanlan2017/blog into HEAD
4cc82482180152616e8cee8a6de919c7eb881053 删除文章中的无效图片,添加新的Git相关的文章,压缩commit
7dccad9a4db12c9a91c25b77ee941cc59e826614 压缩
1a31038c8c3b78e6675489d1af147d9ac2425d72 删除文章中的无效图片,添加新的Git相关的文章
bf682016607be6eabf1952ee9a2ca70c804442aa 添加新的Git相关的文章
9e845cfda2fa63dd4bb7f143a33a53c3308bccf7 删除文章中的无效图片
b9ab7facc769e575b28fefd74e2154fd16087e52 添加新的Git相关的文章
29a6e2b0240c71240146f9a19029d8736055eb5b 添加JS相关文章,更新Git相关文章

现在就可以push了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
lan@DESKTOP-8ISAT6B MINGW64 /e/Blog/blog (master)
$ git push origin master
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 4 threads
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 501 bytes | 501.00 KiB/s, done.
Total 6 (delta 5), reused 0 (delta 0)
remote: Resolving deltas: 100% (5/5), completed with 5 local objects.
remote:
remote: GitHub found 3 vulnerabilities on lanlan2017/blog's default branch (2 high, 1 moderate). To find out more, visit:
remote: https://github.com/lanlan2017/blog/network/alerts
remote:
To github.com:lanlan2017/blog.git
92bf7d3..116161d master -> master

lan@DESKTOP-8ISAT6B MINGW64 /e/Blog/blog (master)
$ git log -10 --pretty=oneline
116161db01c2a19558da0c5b9360c979c46f1205 (HEAD -> master, origin/master, origin/HEAD) 更新文章
......

测试

参考资料

https://www.jianshu.com/p/4a8f4af4e803
https://git-scm.com/docs/git-rebase

fatal: refusing to merge unrelated histories

今天拉取远程分支时报错如下:

1
2
3
4
5
6
7
8
9
10
~/blog/blogRoot   src  git pull origin master
remote: Enumerating objects: 81, done.
remote: Counting objects: 100% (81/81), done.
remote: Compressing objects: 100% (46/46), done.
remote: Total 81 (delta 18), reused 81 (delta 18), pack-reused 0
Unpacking objects: 100% (81/81), done.
From github.com:lanlan2017/lanlan2017.github.io
* branch master -> FETCH_HEAD
+ c900694...4965db5 master -> origin/master (forced update)
fatal: refusing to merge unrelated histories

原因

这是因为我试图把远程的主分支上拉到src分支上。master分支我放的是pages,src分支放源码,这两个分支一开始就没有交集,无法合并。
我这是打错命令了,拉取src分支就好了:

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
 ✘  ~/blog/blogRoot   src  git pull origin src
remote: Enumerating objects: 108, done.
remote: Counting objects: 100% (108/108), done.
remote: Compressing objects: 100% (46/46), done.
remote: Total 97 (delta 52), reused 76 (delta 31), pack-reused 0
Unpacking objects: 100% (97/97), done.
From github.com:lanlan2017/lanlan2017.github.io
* branch src -> FETCH_HEAD
e293673..8ff9c26 src -> origin/src
Updating e293673..8ff9c26
Fast-forward
.travis.yml | 1 +
FM.properties | 5 +
HexoS.bat | 18 ++
source/_posts/index.md | 2 +
.../政策/第三代社保卡.md | 33 +++
...�国互联网企业100强名单.md | 150 +++++++++++++
source/links/index.md | 16 +-
source/todo/index.md | 30 ++-
source/tools/index.md | 23 +-
9 files changed, 263 insertions(+), 15 deletions(-)
create mode 100644 FM.properties
create mode 100644 HexoS.bat
create mode 100644 source/_posts/政策/第三代社保卡.md
create mode 100644 source/_posts/行业/2019年中国互联网企业100强名单.md
~/blog/blogRoot   src  git status
On branch src
Your branch is up to date with 'origin/src'.

nothing to commit, working tree clean
~/blog/blogRoot   src 

JS代码

1
2
3
4
5
6
7
8
9
10
// 启动浏览器下载,文件名为filename,文件内容text中的内容
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
<button onclick="download('helloworld.txt','HelloWorld')">下载</button>
<script>
// 启动浏览器下载,文件名为filename,文件内容text中的内容
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
</script>

效果

点击如下的下载按钮会下载helloworld.txt浏览器中设置的下载位置.

参考资料

https://www.jianshu.com/p/e856f564e44c

protonmail邮箱

官网:https://mail.protonmail.com/
protonmail邮箱为免费用户提供500MB的免费邮箱空间,这个邮箱好就好在不需要验证手机号码,直接注册然后就可以使用了.
不过这也意味值.一旦忘记账户密码了,将无法找回邮箱.
当然你也可以设置另一个常用的邮箱作为验证邮箱以便找回protonmail邮箱密码,但这样就和自己的常用邮箱关联了,还是不要关联的好,免得泄露隐私.

参考资料

https://www.zhihu.com/question/49176007