DDG - remove &ia=

The &ia= parameter doesn't always appear. This removes it to streamline the history log.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         DDG - remove &ia=
// @namespace    https://github.com/Procyon-b
// @version      1.0
// @description  The &ia= parameter doesn't always appear. This removes it to streamline the history log.
// @author       Achernar
// @match        https://duckduckgo.com/*
// @match        https://*.duckduckgo.com/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

(function() {
"use strict";

var hreplaceState=history.replaceState;
history.replaceState=function(a,b,u){
  if (u && u.includes('&ia=')) {
    u=u.replace(/&ia=[^&]+/, '');
    }
  return hreplaceState.apply(history, [a,b,u]);
  }

var hpushState=history.pushState;
history.pushState=function(a,b,u){
  if (u && u.includes('&ia=')) {
    u=u.replace(/&ia=[^&]+/, '');
    }
  return hpushState.apply(history, [a,b,u]);
  }


var inited=0;
function init(){
  if (inited++) return;
  new MutationObserver(function(mutL){
    for(let mut of mutL) {
      if (mut.target && (mut.target.id=='react-duckbar') ) {
        fix(mut.target);
        return;
        }
      }
    }).observe(document.body, { attributes: false, childList: true, subtree: true});
  fix();
  }

function fix(r=document) {
  var a=r.querySelectorAll('a[href*="ia="]');
  for (let i=0,e; e=a[i]; i++) {
    e.search=e.search.replace(/&ia=[^&]+/, '');
    }
  }

if (document.readyState != 'loading') init();
else {
  document.addEventListener('DOMContentLoaded', init);
  window.addEventListener('load', init);
  }


})();