Obsidian-Surfing
Obsidian-Surfing copied to clipboard
Get Current Timestamp from Web Brower时间戳跳转
Bug Description
[Bug]: 设置“Get Current Timestamp from Web Brower”热键获取b站时间戳总是跳转到第一页
例如[03m48s](https://www.bilibili.com/video/BV17F411T7Ao?t=03m48s)
这是由于生成的时间戳链接内不含&p,不适用多集的b站视频
为了达到
[03m48s](https://www.bilibili.com/video/BV17F411T7Ao?t=03m48s&p=139)
的效果
需要将main.js文件getCurrentTimestamp函数做修改
getCurrentTimestamp(editor) { const webContents = import_electron2.remote.webContents.fromId(this.webviewEl.getWebContentsId()); webContents.executeJavaScript(
var time = document.querySelectorAll('.bpx-player-ctrl-time-current')[0].innerHTML;
var timeYMSArr=time.split(':');
var joinTimeStr='00h00m00s';
if(timeYMSArr.length===3){
joinTimeStr=timeYMSArr[0]+'h'+timeYMSArr[1]+'m'+timeYMSArr[2]+'s';
}else if(timeYMSArr.length===2){
joinTimeStr=timeYMSArr[0]+'m'+timeYMSArr[1]+'s';
}
var timeStr= "";
var pageStrMatch = window.location.href.match(/(p=[1-9]{1,})/g);
var pageStr = "";
if(typeof pageStrMatch === "object" && pageStrMatch?.length > 0){
pageStr = '&' + pageStrMatch[0];
}else if(typeof pageStrMatch === "string") {
pageStr = '&' + pageStrMatch;
}
timeStr = window.location.href.split('?')[0]+'?t=' + joinTimeStr + pageStr;
, true).then((result) => { const timestamp ="[" + result.split("?t=")[1].replace(/&p=[1-9]{1,}/g, "") + "](" + result + ")"; const originalCursor = editor?.posToOffset(editor?.getCursor()); editor?.replaceRange(timestamp, editor?.getCursor()); if (originalCursor) editor?.setCursor(editor?.offsetToPos(originalCursor + timestamp.length)); }); }
即可正确使用“Get Current Timestamp from Web Brower”命令
Relevant Screenshot
No response
To Reproduce
No response
Obsidian Version
1.1.9
web-browser-only
- [X] Did you install only one web browser plugin?
Checklist
- [X] I updated to the latest version of the plugin.