提交截拦

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

当前为 2017-07-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        提交截拦
// @author      billypon
// @description 阻止某些输入框按回车时自动提交表单,改为点击默认按钮
// @version     1.10.0
// @namespace   http://www.canaansky.com/
// @match       *://www.123wzwp.com/*
// @match       *://www.678pan.com/*
// @match       *://www.6pan.cc/*
// @match       *://hiyp.cc/*
// @match       *://www.sju.wang/*
// @match       *://www.wwp5.com/*
// @match       *://www.yousupan.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");
		}
}