/*jslint devel: true, browser: true, regexp: true, continue: true, plusplus: true, maxerr: 50, indent: 4 */ /*global unsafeWindow: false, $: false, toastr: false, JSZip: false */ /*global GM_setValue: false, GM_getValue: false, GM_listValues: false, GM_deleteValue: false, GM_addStyle: false, GM_getResourceText: false, GM_xmlhttpRequest: false */ // ==UserScript== // @name MCP :: SRG Mapper // @namespace Lunatrius // @description Apply SRG mappings to code. // @author Lunatrius // @include https://github.com/MinecraftForge/FML* // @include https://github.com/MinecraftForge/MinecraftForge* // @include https://github.com/MinecraftForge/FML/pull/*/files // @include https://github.com/MinecraftForge/MinecraftForge/pull/*/files // @include http://paste.ee/* // @include http://paste.feed-the-beast.com/view/* // @include http://pastebin.com/* // @exclude http://paste.ee/ // @exclude http://pastebin.com/ // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js // @require https://raw.githubusercontent.com/defunkt/jquery-pjax/master/jquery.pjax.js // @require https://raw.githubusercontent.com/Stuk/jszip/master/dist/jszip.min.js // @require https://raw.githubusercontent.com/CodeSeven/toastr/master/build/toastr.min.js // @require http://harvesthq.github.io/chosen/chosen.jquery.js // @resource toast_css https://raw.githubusercontent.com/CodeSeven/toastr/master/build/toastr.min.css // @resource chosen_css http://harvesthq.github.io/chosen/chosen.css // @version 0.1.3 // @grant GM_setValue // @grant GM_getValue // @grant GM_listValues // @grant GM_deleteValue // @grant GM_addStyle // @grant GM_getResourceText // @grant GM_xmlhttpRequest // @grant unsafeWindow // @license MIT // @downloadURL none // ==/UserScript== (function (window) { "use strict"; $.fn.outerHtml = function () { return $("").append(this).html(); }; var mapper = { baseList: "http://export.mcpbot.bspk.rs/", baseMapping: "http://files.minecraftforge.net/maven/de/oceanlabs/mcp/", regexParse: /(func_[0-9]+_[a-z]+_?|field_[0-9]+_[a-z]+_?|p_i?[0-9]+_[0-9]+_?),([^,]+),/i, regexReplace: /\b(?:func_[0-9]+_[a-z]+_?|field_[0-9]+_[a-z]+_?|p_i?[0-9]+_[0-9]+_?)\b/gi, regexMapping: /^(\d+(?:\.\d+)+):((stable)(?:_nodoc)?_(\d+)|(snapshot)(?:_nodoc)?_(\d{8}))$/, mappingList: [], currentMapping: null, mappings: {}, updateIntervalList: 1000 * 3600 * 12, updateIntervalMapping: 1000 * 3600 * 24 * 365, settings: { "github.com": { tag: "li", insert: "div.container>ul.pagehead-actions", container: "#files table tr td.blob-code, .file .type-diff table tr td.blob-code, .inline-review-comment table tr td.blob-code" }, "paste.ee": { tag: "span", insert: ".container>.row>.row>.col-sm-12:has(#download)", container: "#paste-content ol li div", css: [ "#remap_container { float: right; }", "#remap_container a { cursor: pointer; }" ].join("\n") }, "paste.feed-the-beast.com": { tag: "span", insert: "div.col-lg-12>div.detail.by", container: ".CodeMirror ol li span", css: [ "#remap_container { float: right; }", "#remap_container a { cursor: pointer; }" ].join("\n") }, "pastebin.com": { tag: "span", insert: "#code_frame #code_buttons", container: "#code_frame ol li span", css: [ "#remap_container { float: right; margin-top: 4pt; }", "#remap_container a { cursor: pointer; }" ].join("\n") } }, setCurrentMapping: function (mc, type, version) { if (type === undefined && version === undefined) { var mapping = this.parseMapping(mc); this.currentMapping = mapping[0] ? mapping[0] + ":" + mapping[1] + "_" + mapping[2] : null; } else { this.currentMapping = mc + ":" + type + "_" + version; } return this.currentMapping; }, parseMapping: function (mapping) { var m = mapping && mapping.match(/^(\d+(?:\.\d+)+):((stable)(?:_nodoc)?_(\d+)|(snapshot)(?:_nodoc)?_(\d{8}))$/); return m ? [m[1], m[3] || m[5], m[4] || m[6]] : [null, null, null]; }, set: function (key, val) { GM_setValue(key, JSON.stringify(val)); }, get: function (key, def) { try { return JSON.parse(GM_getValue(key, def)) || def; } catch (ignore) {} return def; }, list: function () { return GM_listValues(); }, del: function (key) { GM_deleteValue(key); }, clean: function () { $.each(this.list(), function (index, value) { this.del(value); }.bind(this)); }, time: function () { return new Date().getTime(); }, init: function () { if (window !== window.top) { return; } var css = [ GM_getResourceText("toast_css"), GM_getResourceText("chosen_css") ]; this.settings = this.settings[location.host]; if (!this.settings) { GM_addStyle(css.join("\n")); toastr.info("No settings for " + location.host + "... :("); return this; } if (this.settings.css) { css = css.concat(this.settings.css); } GM_addStyle(css.join("\n")); toastr.options.closeButton = true; toastr.options.showMethod = "slideDown"; toastr.options.hideMethod = "slideUp"; toastr.options.preventDuplicates = true; this.setCurrentMapping(this.get("selected", "")); this.mappingList = this.get("mappings", []); $.each(this.list(), function (index, version) { if (this.regexMapping.test(version) && $.inArray(version, this.mappingList) === -1) { toastr.warning("Removing old mappings...
" + version); this.del(version); this.del(version + "_update"); } }.bind(this)); try { this.main(); } catch (e) { console.log(e); } delete this.init; return this; }, main: function () { this.update(); $("<" + this.settings.tag + ">") .attr("id", "remap_container") .append($("