diff --git a/README.md b/README.md index e89ac6e..0a3128b 100644 --- a/README.md +++ b/README.md @@ -42,30 +42,26 @@ For images that don't have the above those file endings, like say ## Tampermonkey Installation 1. Install the [Tampermonkey](http://tampermonkey.net). -2. Open the [Workflowy Image tampermonkey script](https://raw.githubusercontent.com/jonleung/workflowy-images/master/tampermonkey/workflowy_images_tampermonkey_script.js) and copy the entire contents of that file to your clipboard. -3. Click on your Tampermonkey icon in your Browser and click "Add a new script…" - - > ![](screenshots/github/tampermonkey_installation/new_script.png) - -4. Select everything in the resulting editor and delete it. It should look blank - blank like this: - - > ![](screenshots/github/tampermonkey_installation/delete_script.png) - -5. Now in your empty editor, paste the code in that you just copied from the - other file. - -6. Click the save icon: - - > ![](screenshots/github/tampermonkey_installation/save_script.png) - -5. Then in your browser, refresh your `workflowy.com` window to let the +2. Click install [GreasyFork - workflowy-images-and-bilibili-videos](https://greasyfork.org/zh-CN/scripts/528715-workflowy-images-and-bilibili-videos/code) +3. Then in your browser, refresh your `workflowy.com` window to let the installation take effect. _(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 +- 0.31: + - 增加 webp 格式 + - 修复 mac 不显示 b 站视频问题 + - 改为识别链接而不是内容 + - 上传到 [GreasyFork](https://greasyfork.org/zh-CN/scripts/528715-workflowy-images-and-bilibili-videos/code) + ## Credits I did not come up with this idea. diff --git a/XiaolaiMonoSC-Regular.ttf b/XiaolaiMonoSC-Regular.ttf new file mode 100644 index 0000000..2e4c91c Binary files /dev/null and b/XiaolaiMonoSC-Regular.ttf differ diff --git a/tampermonkey/workflowy_images_tampermonkey_script.js b/tampermonkey/workflowy_images_tampermonkey_script.js index 19cc97e..3f6bd18 100644 --- a/tampermonkey/workflowy_images_tampermonkey_script.js +++ b/tampermonkey/workflowy_images_tampermonkey_script.js @@ -1,26 +1,42 @@ // ==UserScript== -// @name workflowy-images +// @name workflowy-images-and-bilibili-videos // @namespace http://tampermonkey.net/ -// @version 0.2 +// @version 0.31 // @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 +// @license MIT // ==/UserScript== -'use strict'; +"use strict"; -var IMAGE_EXTENSIONS = [".png", ".jpg", ".jpeg", ".gif", ".bmp"]; +// 在脚本最开始的部分,添加这个函数 +function addReferrerMeta() { + const meta = document.createElement('meta'); + meta.name = 'referrer'; + meta.content = 'no-referrer'; + document.head.appendChild(meta); +} + +(function() { + if (document.head) { + addReferrerMeta(); + } else { + document.addEventListener('DOMContentLoaded', addReferrerMeta); + } +})(); + +var IMAGE_EXTENSIONS = [".png", ".jpg", ".jpeg", ".gif", ".bmp", ".webp"]; 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); @@ -42,38 +58,143 @@ function generateImagesForContentNode(node) { function generateImagesForLinkNode(node) { var $node = $(node); + var href = $node.attr('href'); + + // 如果没有 href 属性,直接返回 + if (!href) return; + + var hasImageExtension = IMAGE_EXTENSIONS.some((ext) => + href.toLowerCase().endsWith(ext) + ); + + if (hasImageExtension) { + createImageNodeAfterNode($node.parent().parent(), href); + } +} + +// 添加 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 = $("