Skip to content

Instantly share code, notes, and snippets.

@zhiqiang21
Last active March 25, 2021 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhiqiang21/324ed64c89416a24891b4eccee17ec78 to your computer and use it in GitHub Desktop.
Save zhiqiang21/324ed64c89416a24891b4eccee17ec78 to your computer and use it in GitHub Desktop.
MDN搜索结果自动跳转中文简体页面
// ==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);
})();
@manooog
Copy link

manooog commented Mar 25, 2021

强!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment