您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Simple Tool to Help Name Undeployed Munzees Quicker
当前为
- // ==UserScript==
- // @name nameZee
- // @namespace Rynee
- // @author hugosoft
- // @version 1.0
- // @include http://www.munzee.com/*
- // @include https://www.munzee.com/*
- // @grant unsafeWindow
- // @grant GM_xmlhttpRequest
- // @grant GM_getValue
- // @grant GM_setValue
- // @grant GM_deleteValue
- // @description Simple Tool to Help Name Undeployed Munzees Quicker
- // ==/UserScript==
- //
- //
- //
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function go() {
- var version = "1.2";
- var baseURL = "https://www.munzee.com";
- var virtualImg = 'virtual';
- var currentURL = null;
- var username = null;
- var logonUsername = null;
- var ignoreChars = ['#', '(', ')', '[', ']', '{', '}'];
- /**
- * is value numeric?
- */
- function isNumeric(val){
- return !isNaN(val);
- }
- console.log("nameZee Version: " + version);
- Number.decPoint = '.';
- Number.thousand_sep = ',';
- /**
- * endsWith
- */
- String.prototype.endsWith = function(suffix) {
- return this.indexOf(suffix, this.length - suffix.length) !== -1;
- };
- /**
- * startsWith
- * */
- String.prototype.startsWith = function( prefix ) {
- return this.substring( 0, prefix.length ) === prefix;
- }
- /**
- * replaceAll
- */
- String.prototype.replaceAll = function (find, replace) {
- var str = this;
- return str.replace(new RegExp(find, 'g'), replace);
- };
- /**
- * contains
- * */
- String.prototype.contains = function() {
- return String.prototype.indexOf.apply( this, arguments ) !== -1;
- };
- /**
- * extract logonUsername from profile link
- * */
- function getLogonUsername() {
- try {
- //search menu (ul)
- var container = $($(".user-menu"));
- //first li
- container = $(container.children().first());
- //first a
- container = $(container.children().first());
- //attribute href
- container = container.attr('href');
- //console.log(container);
- //token with username in href
- var res = container.split("/");
- //console.log(res);
- var logonUsername = res[res.length-2];
- return logonUsername;
- } catch (e) {
- console.log(e);
- }
- }
- $(document).ready(function() {
- //checkForUpdate();
- currentURL = new String(document.URL);
- if (!currentURL.endsWith("/")) {
- currentURL = currentURL + "/";
- }
- username = $(".avatar-username").text();
- if (username==undefined || username.length<1) {
- username = null;
- }
- logonUsername = getLogonUsername();
- if (logonUsername==undefined || logonUsername.length<1) {
- logonUsername = null;
- }
- //rename undeploys
- if (username!=null && logonUsername==username && currentURL.toLowerCase().startsWith(baseURL + '/m/' + username.toLowerCase() + "/undeploys/")) {
- //new action button
- var container = $('.page-header');
- container = $(container).find('.pull-right');
- var buttonCode = '<div class="pull-right"><a id="renumberUndeploys" class="btn green" style="margin-left:10px;margin-right:10px">renumber</a></div>';
- var optionCode = '<div class="pull-right"><select id="selBracket" class="form-control"><option value="curlyBracket">{ }</option><option value="squareBracket">[ ]</option><option value="roundBracket">( )</option><option selected value="hash">#</option><option value="blank"> </option></select></div>';
- $(container).append(optionCode+buttonCode);
- //button event
- $("#renumberUndeploys").click(function() {
- doRenumber();
- });
- }
- //rename deploys
- /*if (username!=null && logonUsername==username && currentURL.toLowerCase().startsWith(baseURL + '/m/' + username.toLowerCase() + "/deploys/")) {
- //new action button
- var container = $('.page-header');
- container = $(container).find('h2');
- $(container).append(' <div class="pull-right"><a id="renumberDeploys" class="btn green" style="margin-left:10px">renumber</a></div><div class="clearfix"></div>');
- //button event
- $("#renumberDeploys").click(function() {
- doRenumber();
- });
- }*/
- });
- /**
- * prefix for number
- * */
- function getPrefix() {
- if ($( "#selBracket" ).val()=='hash') {
- return "#";
- }
- if ($( "#selBracket" ).val()=='curlyBracket') {
- return '{';
- }
- if ($( "#selBracket" ).val()=='squareBracket') {
- return '[';
- }
- if ($( "#selBracket" ).val()=='roundBracket') {
- return '(';
- }
- if ($( "#selBracket" ).val()=='blank') {
- return ' ';
- }
- return '[';
- }
- /**
- * suffix for number
- * */
- function getSuffix() {
- if ($( "#selBracket" ).val()=='hash') {
- return "";
- }
- if ($( "#selBracket" ).val()=='curlyBracket') {
- return '}';
- }
- if ($( "#selBracket" ).val()=='squareBracket') {
- return ']';
- }
- if ($( "#selBracket" ).val()=='roundBracket') {
- return ')';
- }
- if ($( "#selBracket" ).val()=='blank') {
- return '';
- }
- return '';
- }
- /**
- * rename undeploys and deploys
- * */
- function doRenumber() {
- var sections = $("section").get();
- var count=0;
- //inspect each section
- for ( var i = 0; i < sections.length; i++ ) {
- if(isRenumber(getFriendlyName(sections[i]), getLfdNr(sections[i])) && !isVirtual(sections[i])) {
- parseSectionTimeoutWrapper(count++, sections[i]);
- } else {
- console.log("IGNRORED::" + getFriendlyName(sections[i]) + " virtual=" + isVirtual(sections[i]));
- }
- }
- }
- /** just a wrapper for parseSection with timeout*/
- function parseSectionTimeoutWrapper(i, section) {
- setTimeout(function() {
- parseSection(i, section);
- }, 1500*i);
- }
- /**
- * parseSection of munzees and call post-method for renumbering
- */
- function parseSection(i, section) {
- var lfdNr = getLfdNr(section);
- var originalFriendlyName = getFriendlyName(section);
- if(isRenumber(originalFriendlyName, getLfdNr(section)) && !isVirtual(section)) {
- var adminURL = 'https://www.munzee.com/m/' + username + '/' + lfdNr + "/admin/";
- var oldFriendlyName = removeGeneratedNumber(originalFriendlyName);
- var newFriendlyName = oldFriendlyName + " " + getPrefix() + lfdNr + getSuffix();
- console.log(adminURL + ":: " + originalFriendlyName + "->" + newFriendlyName);
- $.post(adminURL, { friendly_name: ""+newFriendlyName, notes:""}, function(result) {
- //console.log(result);
- });
- }
- }
- /**
- * remove the generated Number of friendly name
- */
- function removeGeneratedNumber(friendlyName) {
- while (friendlyName.length>0 && isNumeric(friendlyName[friendlyName.length-1])) {
- friendlyName = friendlyName.substr(0,friendlyName.length-1);
- console.log(friendlyName);
- }
- return friendlyName;
- }
- /**
- * is value numeric?
- */
- function isNumeric(val){
- return !isNaN(val);
- }
- /** get lfdNr of current section*/
- function getLfdNr(section) {
- var munzeeURL = baseURL + $(section).find('a').attr('href');
- arr = munzeeURL.split("/");
- return arr[5];
- }
- /** get friendlyName of current section*/
- function getFriendlyName(section) {
- var friendlyName = $(section).find("a")[1];
- return $(friendlyName).text();
- }
- /** renumbering permitted? */
- function isRenumber(friendlyName, munzeeNumber) {
- friendlyName = friendlyName.trim();
- //for (i=0; i <ignoreChars.length; i++) {
- if (friendlyName.contains(munzeeNumber)) {
- return false;
- }
- //}
- return true;
- }
- function isVirtual(section) {
- var imgageSrc = $(section).find(".pin").attr('src');
- return imgageSrc.contains(virtualImg);
- }
- } // end go
- // jQuery workaround for Chrome
- // a function that loads jQuery and calls a callback function when jQuery has finished loading
- function addJQuery(callback) {
- var script = document.createElement("script");
- script.textContent = "(" + callback.toString() + ")();";
- document.body.appendChild(script);
- }
- // load jQuery and execute
- addJQuery(go);