DDG - remove &ia=

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
  }


})();