提交截拦

阻止某些输入框按回车时自动提交表单,改为点击默认按钮

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        提交截拦
// @author      billypon
// @description 阻止某些输入框按回车时自动提交表单,改为点击默认按钮
// @version     1.10.4
// @namespace   http://www.canaansky.com/
// @match       *://www.123wzwp.com/*
// @match       *://www.678pan.net/*
// @match       *://www.88pan.cc/*
// @match       *://hiyp.cc/*
// @match       *://www.sju.wang/*
// @match       *://www.wwp5.com/*
// @match       *://www.yousuwp.com/*
// @run-at      document-idle
// @grant       none
// ==/UserScript==

var domain = location.hostname.match(/\w+\.\w+$/)[0], path=location.pathname;
console.debug("domain", domain);

function prevent(input, button, element) {
	if (!element)
		element = document;
	input = element.querySelector(input);
	button = element.querySelector(button);
	console.debug("input", input);
	console.debug("button", button);
	if (!(input && button))
		return;
	input.addEventListener("keydown", function (event) {
		console.debug("keyCode", event.keyCode);
		if (event.keyCode != 13)
			return;
		button.click();
		event.preventDefault();
	});
}

function listen(dialog, input, button) {
	var handler = function (event) {
		var target = event.target, list = target.classList;
		if (!list || !list.contains(dialog))
			return;
		console.debug("dialog", target);
		removeEventListener("DOMNodeInserted", handler);
		setTimeout(function () {
			prevent(input, button, target);
		});
	}
	addEventListener("DOMNodeInserted", handler);
}

function startsWith(search, string) {
	search = search || "/down-";
	return (string || path).slice(0, search.length) == search;
}

switch (domain) {
	default:
		if (startsWith()) {
			prevent("#code", "#s1");
		}
}