Welfare of kids shoes-GitHub Chinese INS, kids shoes-github

Source: Internet
Author: User

Welfare of kids shoes-GitHub Chinese INS, kids shoes-github

I am very excited to see a plug-in a front-end group today! I will share the steps for implementing the plug-in!

After the plug-in layout is complete, it will inevitably be a little excited! I removed the chrome plug-in Tampermonkey_v4.0.25.crx and added the new script to main. js. It is also finished. I feel no difference!

If the plug-in downloaded by github is slow, add the main. js Code directly to the new script following the steps above!

Attached main. js:

/// = UserScript ==/// @ name: GitHub Chinese ins // @ description: Some menu and content on the Chinese GitHub interface. // @ Copyright 2016, floor Instructor ( http://www.52cik.com/ ) // @ Icon https://assets-cdn.github.com/pinned-octocat.svg// @ Version 1.6.3 // @ author floor instructor // @ license MIT // @ homepageURL https://github.com/52cik/github-hans// @ Match http: // * .github.com/#// @ match https: // * .github.com/#// @ require https://52cik.github.io/github-hans/locals.js?v1.6.3// @ Run-at document-end // @ grant none // =/UserScript = (function (window, document, undefined) {'use strict '; var lang = 'zh '; // Chinese // github loads jquery with amd and does not expose it to the global environment. Var $ = require ('github/jquery ') ['default']; // the page to be translated var page = getPage (); transTitle (); // page title translation timeElement (); // time node translation contributions (); // contribution calendar translation (calendar is embedded or ajax, so Processing Based on callback events) walk (document. body); // translate the page immediately $ (document ). ajaxComplete (function () {transTitle (); walk (document. body); // translate the page again after ajax request});/*** traverse node ** @ param {Element} node */function walk (node) {var nodes = node. childNodes; For (var I = 0, len = nodes. length; I <len; I ++) {var el = nodes [I]; // todo 1. fixed the problem of multi-attribute translation. 2. add event translation, such as Preview information; if (el. nodeType = Node. ELEMENT_NODE) {// Element Node processing // Element Node attribute translation if (el. tagName = 'input' | el. tagName = 'textea ') {// input box button text field if (el. type = 'button '| el. type = 'submit ') {transElement (el, 'value');} else {transElement (el, 'placeholder');} else if (el. hasAttribute ('a Ria-label ') {// The element with a prompt, such as the transElement (el, 'aria-label', true) of the tooltip effect; if (el. hasAttribute ('data-copied-hint') {// transElement (el. dataset, 'copiedhint');} else if (el. tagName = 'optgroup') {// translate the <OPTGROUP> label attribute transElement (el, 'label');} if (el. hasAttribute ('data-disable-with') {// The button waits for the prompt transElement (el. dataset, 'disablewith ');} // skip readme, the file list, and the code displays if (el. I D! = 'Readme '&&! I18N. conf. reIgnore. test (el. className) {walk (el); // traverse sub-nodes} else if (el. nodeType = Node. TEXT_NODE) {// text node translation transElement (el, 'data') ;}}/ *** get translation page */function getPage () {// first match the class var page of the body = document. body. className. match (I18N. conf. rePageClass); if (! Page) {// The extended url matches page = location. href. match (I18N. conf. rePageUrl);} if (! Page) {// The extension pathname matches page = location. pathname. match (I18N. conf. rePagePath);} return page? Page [1] | 'homepage': false; // retrieve the page key}/*** translate the page title */function transTitle () {var title = translate (document. title, 'title'); if (title = false) {// exit return false if there is no translation;} document. title = title ;} /*** translation node attribute content ** @ param {object} el object * @ param {string} field attribute field * @ param {boolean} whether isAttr is an attr attribute **@ returns {boolean} */function transElement (el, field, isAttr) {var transText = False; // the translated text if (isAttr === undefined) {// non-attribute translation transText = translate (el [field], page );} else {transText = translate (el. getAttribute (field), page);} if (transText = false) {// exit return false if there is no translation ;} // Replace the translated content if (isAttr === undefined) {el [field] = transText;} else {el. setAttribute (field, transText);}/*** translation text ** @ param {string} text to be translated string * @ param {string} page field **@ Returns {string | boolean} */function translate (text, page) {// translate var str; var _ key = text. trim (); // remove the key var _ key_neat = _ key. replace (// xa0/g, '') // replace the bug caused by & nbsp; space. replace (// \ s {2,}/g, ''); // Remove extra characters such as leading spaces (in the test phase, recover if any problem occurs) if (_ key_neat = '') {return false;} // if the content is null, str = transPage ('pubilc', _ key_neat) is not translated ); // public translation if (str! = False & str! ==_ Key_neat) {// public translation completed str = transPage ('pubilc', str) | str; // secondary public translation (to make up for partial Regular Expression translation) return text. replace (_ key, str); // replace the original character, retain the blank part} if (page = false) {return false ;} // if the unknown page does not translate str = transPage (page, _ key_neat); // if (str = false | str = '') {return false;} // do not translate unknown content str = transPage ('pubilc', str) | str; // secondary public translation (to compensate for partial Regular Expression translation) return text. replace (_ key, str); // replace the original character to ensure Leave blank part}/*** translation page content ** @ param {string} page * @ param {string} key to be translated ** @ returns {string | boolean }* /function transPage (page, key) {var str; // translation result var res; // regular array // static translation str = I18N [lang] [page] ['static '] [key]; if (str) {return str;} // regular translation res = I18N [lang] [page]. regexp; if (res) {for (var I = 0, len = res. length; I <len; I ++) {str = key. replace (res [I] [0], res [I] [1]); if (str! = Key) {return str ;}} return false; // no translation entries}/*** time node translation */function timeElement () {if (! Window. relativeTimeElement) {// prevent return;} var RelativeTimeElement $ getFormattedDate = RelativeTimeElement. prototype. getFormattedDate; var timeagelement $ getFormattedDate = timeagelement. prototype. getFormattedDate; // var LocalTimeElement $ getFormattedDate = LocalTimeElement. prototype. getFormattedDate; var RelativeTime = function (str, el) {// relative time parsing if (/^ on ([\ w] +) $ /. test (str) {return' '+ El. title. replace (/. + $/, '');} // use the relative time of the Second Regular Expression for public dictionary translation var time_ago = I18N [lang]. pubilc. regexp [1]; return str. replace (time_ago [0], time_ago [1]) ;}; RelativeTimeElement. prototype. getFormattedDate = function () {var str = RelativeTimeElement $ getFormattedDate. call (this); return RelativeTime (str, this) ;}; timeagelement. prototype. getFormattedDate = function () {var str = timeago element $ getForm AttedDate. call (this); return RelativeTime (str, this) ;}; LocalTimeElement. prototype. getFormattedDate = function () {return this. title. replace (/. + $/, '') ;}; // traverse the time element for translation // github revision, no longer using the time tag. $ ('Time, relative-time, time-ago, local-time '). each (function (I, el) {if (el. getFormattedDate) {// skip the unregistered time element el. textContent = el. getFormattedDate () ;}});}/*** contribution Calendar Based on Event translation */function contributions () {var tip = document. getElementsByClassName ('svg-tip-one-line'); // wait until the IncludeFragmentElement element is loaded and then bind the event var observe = require ('github/observ '). observe; observe (". js-calendar-graph-svg ", function () {setTimeout (function () {// delayed binding of the mouseover event, otherwise var $ calendar =$ ('. js-calendar-graph '); walk ($ calendar [0]); // translate the calendar section $ calendar. on ('mouseover ','. day ', function () {if (tip. length = 0) {// exit when no tip element exists to prevent return true;} var data = $ (this ). data (); // obtain the data var $ tip =$ (tip [0]) on the node; $tip.html (data. count + 'subcontribution '+ data. date); var rect = this. getBoundingClientRect (); // obtain the element position var left = rect. left + window. pageXOffset-tip [0]. offsetWidth/2 + 5.5; effectip.css ('left', left) ;}) ;}, 999) ;}) (window, document );View Code

Although the translation is not complete, the basic use is still correct.

The author of this plug-in is constantly updating. Keep an eye on it. If you have time, check the updates!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.