Remove Text Fragment

Remove Text Fragment from Google search result URLs

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name            Remove Text Fragment
// @name:ja         Text Fragmentの削除
// @namespace       https://greasyfork.org/users/783910
// @version         0.5.1
// @description     Remove Text Fragment from Google search result URLs
// @description:ja  Google検索結果のURLからText Fragmentを削除する
// @author          ysnr777
// @match           https://www.google.com/search?*
// @grant           none
// @license         WTFPL
// @run-at          document-end
// ==/UserScript==

'use strict';

const targetQuery = "a[href*=':~:']";
const regex = /#:~:[^"]*/;
const observeId = 'center_col';

const removeFragment = target => {
  for (const el of target.querySelectorAll(targetQuery)) {
    el.href = el.href.replace(regex, '');
  }
};

removeFragment(document);

const observer = new MutationObserver((mutations, observer) => {
  for (const record of mutations) {
    for (const node of record.addedNodes) {
      removeFragment(node);
    }
  }
});
observer.observe(
  document.getElementById(observeId),
  {
    childList: true,
    subtree: true
  }
);
window.addEventListener('beforeunload', () => {
  observer.disconnect();
});