Keul Bookmark

un double clic dans le texte sauvegarde la position dans l'URL / Recharger la page la fait défiler sur la position

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name     Keul Bookmark
// @version  1
// @grant    none
// @match    *://*/*
// @description un double clic dans le texte sauvegarde la position dans l'URL / Recharger la page la fait défiler sur la position
// @namespace https://greatest.deepsurf.us/users/805853
// ==/UserScript==


window.addEventListener("load", load_bookmark);
window.addEventListener("dblclick", save_bookmark);

function save_bookmark() {
  var userSelection = window.getSelection ? window.getSelection() : document.selection.createRange();
  var nodePosition = 0;
  var nodeIterator = document.createNodeIterator(document.body,NodeFilter.SHOW_TEXT);
  while (currentNode = nodeIterator.nextNode()) {
    nodePosition++;
    if(currentNode==userSelection.anchorNode) {
      return window.location.hash = "#bookmark-" + nodePosition + "-" + userSelection.anchorOffset;
    }
  }
}

function load_bookmark() {
  var bookmark=window.location.hash.split("-")
  if(bookmark[0]!='#bookmark' || bookmark.length!=3) return;
  var nodePosition = 0;
  var nodeIterator = document.createNodeIterator(document.body,NodeFilter.SHOW_TEXT);
  while (currentNode = nodeIterator.nextNode()) {
    nodePosition++;
    if(nodePosition == bookmark[1]) {
      var backupNode = currentNode.cloneNode(true);
      var startText = document.createTextNode(currentNode.data.substring(0,bookmark[2]));
      var endText = document.createTextNode(currentNode.data.substring(bookmark[2],currentNode.data.length));
      var bookmarkText = document.createElement("span")
      bookmarkText.setAttribute("style","height:0.7em;display:inline-block;border:2px solid red;");
      var finalNode = document.createElement("span");
      finalNode.appendChild(startText);
      finalNode.appendChild(bookmarkText);
      finalNode.appendChild(endText);
      currentNode.parentNode.replaceChild(finalNode,currentNode);
      bookmarkText.scrollIntoView({behavior: "smooth", block: "center", inline: "center"});
      // currentNode.parentNode.replaceChild(backupNode, currentNode); // put old text back after scroll?
      return;
    }
  }
}