Last active
March 25, 2021 10:49
-
-
Save zhiqiang21/324ed64c89416a24891b4eccee17ec78 to your computer and use it in GitHub Desktop.
MDN搜索结果自动跳转中文简体页面
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name MDN自动转化中文简体 | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match *://developer.mozilla.org/* | |
// @run-at document-end | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
setTimeout(function(){ | |
var optionValue = 'zh-CN'; | |
var selectObj = document.querySelector('select#language'); | |
var formData = document.querySelector('.languages.go'); | |
var defaultSelectIndex = selectObj.selectedIndex; | |
var defaultValue = selectObj.options[defaultSelectIndex].value; | |
if (!(/zh-CN/.test(location.href))) { | |
if (defaultValue.indexOf(optionValue) < 0) { | |
for (var i = 0, len = selectObj.length; i < len; i++) { | |
if (selectObj.options[i].value.indexOf(optionValue) > 0) { | |
formData.attributes.action = selectObj.options[i].value; | |
// 某些页面是默认提交表单表单连接为action的value | |
if (formData.attributes.action) { | |
location.href = selectObj.options[i].value; | |
} else { | |
selectObj.options[i].selected = true; | |
formData.submit(); | |
} | |
break; | |
} | |
} | |
} | |
} | |
return; | |
},1000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
强!