notion formula clickable url generator

Used to add a clickable button to urls generated by custom formula in notion

  1. // ==UserScript==
  2. // @name notion formula clickable url generator
  3. // @version 0.1
  4. // @description Used to add a clickable button to urls generated by custom formula in notion
  5. // @author Hibem
  6. // @match https://www.notion.so/*
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=notion.so
  8. // @grant none
  9. // @namespace https://gf.qytechs.cn/users/301775
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. var I = 0;
  15. const getDom = setInterval(() => {
  16. if(!document.querySelector("a.newurlsign")){
  17. I = 0
  18. }
  19. if (document.evaluate('//div[contains(text(), "http")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength-1>I){//Fill "dom" with target dom
  20. //code start
  21. console.log(I)
  22. console.log(document.evaluate('//div[contains(text(), "http")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null).snapshotLength-1)
  23. addUrl()
  24. //code end
  25. // clearInterval(getDom)
  26. }
  27. },500)
  28.  
  29.  
  30. function addUrl(){
  31. var urlDom = document.evaluate('//div[contains(text(), "http")]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null )
  32. for ( var i=0 ; i < urlDom.snapshotLength; i++ )
  33. {
  34. var newurl = document.createElement("a")
  35. newurl.innerHTML = 'via'
  36. newurl.setAttribute("href",urlDom.snapshotItem(i).textContent)
  37. newurl.setAttribute("target","_blank")
  38. newurl.setAttribute("class","newurlsign")
  39. newurl.setAttribute("style",`
  40. position:absolute;
  41. left:${urlDom.snapshotItem(i).getBoundingClientRect().left-324}px;
  42. z-index:1000;
  43. cursor: pointer;
  44. border-bottom-right-radius: 4px;
  45. padding: 2px 6px 4px;
  46. font-size: 11px;
  47. line-height:1.1;
  48. background: rgb(35, 131, 226);
  49. color: white;
  50. text-decoration: none;
  51. `)
  52. urlDom.snapshotItem(i).parentNode.parentNode.appendChild(newurl)
  53. I=i;
  54.  
  55. }
  56. return I
  57. }
  58.  
  59.  
  60. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址