WF ToolBox Lib Alpha

When prema is present to offer his version for beta + classic editor and add the profile editor waze

目前為 2020-11-25 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/416769/873075/WF%20ToolBox%20Lib%20Alpha.js

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name            WF ToolBox Lib Alpha
// @namespace       WFTB_ns
// @version         0.0.1.6
// @description:en  When prema is present to offer his version for beta + classic editor and add the profile editor waze
// @description:fr  Quand un perma est présent proposer sa version pour l'éditeur beta + classique et ajout du editor profile waze
// @author          exolium
// @copyright       2015-2020 exolium
// @licence         GNU GPL v2
// @grant           GM_xmlhttpRequest
// @description When prema is present to offer his version for beta + classic editor and add the profile editor waze
// ==/UserScript==

//============================== Options ================================//
var WFTB_lang_en = 0;
var WFTB_lang_fr = 1;

var WFTB_label_setting_manager = ['Settings Manager', 'Gestionnaire de Paramètres'];
var WFTB_label_close = ['Close', 'Fermer'];
var WFTB_Log_level = 5; // 0 = no log / 1 = error / 2 = warn / 3 = min log / 4 = Medium Log / 5 = high detail Log
var WFTB_targetblank = true;
var WFTB_use_layer = true;
var WFTB_button_beta = 'Beta';
var WFTB_button_prod = 'Prod';
var WFTB_button_editorprofil = 'Editor Profil A';
var WFTB_lang = WFTB_lang_en;

//============================== Var ====================================//
var WFTB_beta_editor_verify = false;
var WFTB_beta_editor = false;
var WFTB_profil = Array();
var WFTB_Settings = {};

//============================== URL ====================================//
var WFTB_URL_protocol = window.location.protocol + '//';
var WFTB_URL_Base = window.location.hostname;
var WFTB_URL_usergroups = WFTB_URL_protocol + WFTB_URL_Base + '/forum/ucp.php?i=167';
var WFTB_URL_UserProfil_URI = '/user/editor/';

//============================== Recherche ==============================//
var WFTB_search_base_url = '//a[contains(@href,\'editor-beta.waze.com\') or (@href,\'beta.waze.com\') or contains(@href,\'www.waze.com\')][contains(@href,\'editor\')]';
var WFTB_search_perma_layer = 'layers=w+';
var WFTB_search_usergroups_memberships = '//*[@id="ucp"]/div[1]/div/ul[2]';
var WFTB_search_usergroups_memberships_groups = ['//*[@id="ucp"]/div[1]/div/ul[2]/li','//*[@id="ucp"]/div[1]/div/ul[4]/li'];
var WFTB_search_usergroups_name = '';
var WFTB_search_usergroups_if_leadersheep = '//*[@id="ucp"]/div[1]/div/ul[1]/li/dl/dt';
var WFTB_search_Lang_Selector = '/html/body/div[3]/div[1]/div[6]/div';
var WFTB_search_linklist = '//*[@id="wrap"]/div[2]/div/ul[2]/li[2]';

//============================== Library : log ==========================//
function WFTB_Log(WFTB_L_function, WFTB_L_type, WFTB_L_text) {
 WFTB_L_text = 'Waze ' + GM_info.script.name
        + ' ' + GM_info.script.version
        + ' ' + WFTB_L_function
        + ' : ' + WFTB_L_text;

 switch(WFTB_L_type) {
  case 1 : // error
   if(WFTB_Log_level > 0) console.error(WFTB_L_text);
   break;
  case 2 : // warn
   if(WFTB_Log_level > 1) console.warn(WFTB_L_text);
   break;
  case 3 : // min log
   if(WFTB_Log_level > 2) console.info(WFTB_L_text);
   break;
  case 4 : // Medium Log
   if(WFTB_Log_level > 3) console.info(WFTB_L_text);
   break;
  case 5 : // high detail Log
   if(WFTB_Log_level > 4) console.info(WFTB_L_text);
   break;
  default: // no log
   return;
 }
}

//============================== WFTB_updatePerma ======================//
function WFTB_checkupdate() {
 WFTB_Log('WFTB_checkupdate', 4, 'End');

 WFTB_Log('WFTB_checkupdate', 5, 'WFTB_Settings.version=' + WFTB_Settings.version);
 WFTB_Log('WFTB_checkupdate', 5, 'GM_info.script.version=' + GM_info.script.version);

 if(WFTB_Settings.version != GM_info.script.version) {
  WFTB_Settings.version = GM_info.script.version;
  localStorage.WFTB_data = JSON.stringify(WFTB_Settings);
  WFTB_Log('WFTB_checkupdate', 5, JSON.stringify(WFTB_Settings));
 }

 if(WFTB_Settings.app_name != GM_info.script.name) {
  WFTB_Settings.app_name = GM_info.script.name;
  localStorage.WFTB_data = JSON.stringify(WFTB_Settings);
  WFTB_Log('WFTB_checkupdate', 5, JSON.stringify(WFTB_Settings));
 }

 WFTB_Log('WFTB_checkupdate', 4, 'End');
}

//============================== Library : Version type ========================//
function WFTB_version(){
 var return_version;
 var WFTB_version_prod = new RegExp("^(?:[0-9]{1,10}\.){1}[0-9]{1,10}$");
 var WFTB_version_beta = new RegExp("^(?:[0-9]{1,10}\.){2}[0-9]{1,10}$");
 var WFTB_version_alpha = new RegExp("^(?:[0-9]{1,10}\.){3}[0-9]{1,10}$");

 if (WFTB_version_alpha.test(WFTB_Settings.version)) {
  WFTB_Log_level = 5 
  return 'alpha';
 } else if (WFTB_version_beta.test(WFTB_Settings.version)) {
  WFTB_Log_level = 3
  return 'beta';
 } else if (WFTB_version_prod.test(WFTB_Settings.version)) {
  WFTB_Log_level = 1
  return 'prod';
 } else return false;
}

//============================== Library : WFTB_insertAfter ============//
function WFTB_insertAfter(WFTB_L_element, WFTB_L_target) {
 WFTB_Log('WFTB_insertAfter', 4, 'Start');
 WFTB_L_target.parentNode.insertBefore(WFTB_L_element, WFTB_L_target.nextSibling);
 WFTB_Log('WFTB_insertAfter', 4, 'End');
}

//============================== Library : xpath ========================//
function WFTB_xpath(WFTB_L_query, WFTB_L_element) {
 WFTB_Log('WFTB_xpath', 4, 'Start');

 var WFTB_L_result = document.evaluate(WFTB_L_query, WFTB_L_element, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
 var WFTB_L_table = new Array();
 var WFTB_L_cpt = 0;

 for (WFTB_L_cpt = 0; WFTB_L_cpt < WFTB_L_result.snapshotLength; WFTB_L_cpt++) WFTB_L_table.push(WFTB_L_result.snapshotItem(WFTB_L_cpt));
 WFTB_Log('WFTB_xpath', 4, 'End');
 return WFTB_L_table;
}

function WFTB_single_xpath(WFTB_L_query, WFTB_L_element) {
 WFTB_Log('WFTB_single_xpath', 4, 'Start');
 var WFTB_L_elmFirstResult = document.evaluate(WFTB_L_query, WFTB_L_element, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
 WFTB_Log('WFTB_single_xpath', 4, 'End');
 return WFTB_L_elmFirstResult;
}

//=======================================================================//