Query String Automator

Automation based on query string. Example: https://www.google.com/?uauto={selector:".RNmpXc",action:"this.click()"}

目前為 2023-11-04 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Query String Automator
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Automation based on query string. Example: https://www.google.com/?uauto={selector:".RNmpXc",action:"this.click()"}
// @author       You
// @match        *://*/*?uauto=*
// @run-at       document-idle
// @grant        none
// ==/UserScript==

(function () {
  /** @type {string} A query string. object literal of the automation*/
  const queryString = new URLSearchParams(window.location.search);

  /**
   * @typedef {object} automation
   * @prop {string} selector Selector to the target element
   * @prop {string=} action If empty, click the target. Otherwise, eval it. ('this' is binded to the target element)
   */
  let uauto = eval(`(${queryString.get("uauto")})`);
  /**@type {automation[]} */
  let automations = uauto?.length ? uauto : [uauto];
  for (let { selector, action } of automations) {
    let target = document.querySelector(selector);
    console.log(target);
    if (!target) {
      return;
    }
    if (!action) {
      target.click();
    } else {
      var fn = eval(`(function() {${action}})`);
      fn.call(target);
    }
  }
})();