From 49e1a9397ca86ac026e04c6f6f622952d40b73cb Mon Sep 17 00:00:00 2001 From: eterlan <703246769@qq.com> Date: Mon, 3 Mar 2025 23:28:37 +0800 Subject: [PATCH 1/5] ver 0.3 --- README.md | 7 + .../workflowy_images_tampermonkey_script.js | 148 +++++++++++++++--- 2 files changed, 130 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index e89ac6e..c98ab8e 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,13 @@ _(Credit for the Tampermonkey installation directions go to Frank Degenaar. I took the directions and screenshots he wrote from [the blogpost he wrote on the Workflowy Site](https://blog.workflowy.com/2016/01/06/inline-images/)._ +## Version History + +- 0.3: + - Add support for Bilibili videos. + - Remove images once link is removed. + - Fix some bugs + ## Credits I did not come up with this idea. diff --git a/tampermonkey/workflowy_images_tampermonkey_script.js b/tampermonkey/workflowy_images_tampermonkey_script.js index 19cc97e..ac03d82 100644 --- a/tampermonkey/workflowy_images_tampermonkey_script.js +++ b/tampermonkey/workflowy_images_tampermonkey_script.js @@ -1,26 +1,25 @@ // ==UserScript== -// @name workflowy-images +// @name workflowy-images-and-bilibili-videos // @namespace http://tampermonkey.net/ -// @version 0.2 +// @version 0.3 // @description Embed image links into workflowy -// @author Jonathan Leung (https://github.com/jonleung) +// @author Jonathan Leung (https://github.com/jonleung)&eterlan(https://github.com/eterlan) // @match https://workflowy.com/* // @grant none +// @require https://code.jquery.com/jquery-3.6.0.min.js +// @require https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.1/underscore-min.js // ==/UserScript== -'use strict'; +"use strict"; var IMAGE_EXTENSIONS = [".png", ".jpg", ".jpeg", ".gif", ".bmp"]; function createImageNodeAfterNode($node, imgSrc) { if ($node.parent().find(".content-img").length === 0) { - var $div = $("
") - .addClass("content-img"); - var $img = $("") - .attr("src", imgSrc) - .css({ - "max-width": "100%", - "max-height": "350px" - }); + var $div = $("
").addClass("content-img"); + var $img = $("").attr("src", imgSrc).css({ + "max-width": "100%", + "max-height": "350px", + }); $div.append($img); $node.after($div); @@ -44,36 +43,135 @@ function generateImagesForLinkNode(node) { var $node = $(node); var url = $node.text(); - var curExtension = url.substr(-4); - if (_.contains(IMAGE_EXTENSIONS, curExtension) && $node.parent().text()[0] !== "!") { - createImageNodeAfterNode($node.parent(), url); + var hasImageExtension = IMAGE_EXTENSIONS.some((ext) => + url.toLowerCase().endsWith(ext) + ); + if (hasImageExtension) { + createImageNodeAfterNode($node.parent().parent(), url); + } +} + +// 添加 B 站视频 ID 提取函数 +function getBilibiliVideoId(url) { + const bvMatch = url.match(/BV\w{10}/); + return bvMatch ? bvMatch[0] : null; +} + +function createBilibiliIframeAfterNode($node, videoId) { + if ($node.parent().find(".content-video").length === 0) { + var $div = $("
").addClass("content-video"); + var $iframe = $("