Evil Link Converter triggered onmouse

I try to pretend evil Facebook's method.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Evil Link Converter triggered onmouse
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  I try to pretend evil Facebook's method.
// @author       eggplants
// @homepage     https://github.com/eggplants
// @match        https://twitter.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

/*jshint esversion: 6 */

(function () {
  "use strict";

  const target = "https://google.com";
  var buf = "";
  function uuidv4() {
    return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
      (
        c ^
        (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))
      ).toString(16)
    );
  }
  function main(){
    Array.from(document.getElementsByTagName("a")).forEach((elm) => {
    if (elm.onmousedown === null) {
      if(elm.id === ""){
          elm.id = uuidv4();
      }
      elm.onmousedown = ({elm: elm}) => {
        doChange(elm.id);
      };
      if(elm.onmouseup === null) {
          elm.onmouseup = ({elm: elm}) => {
            undoChange(elm.id);
          };
      }
      if(elm.onmouseleave===null){
          elm.onmouseleave = ({elm: elm}) => {
        undoChange(elm.id);
      };
    }}
  });}
  function doChange(id) {
    var e = document.getElementById(id);
    if (e.href !== target) {
      [buf, e.href] = [e.href, target];
    }
  }
  function undoChange(id) {
    var e = document.getElementById(id);
    if (e.href === target) {
      e.href = buf;
    }
  }
})();