您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Automatically check promotion details according to title contents
当前为
// ==UserScript== // @name Automatically Check Promotion Details // @version 3.9 // @description Automatically check promotion details according to title contents // @author Tiger // @match http://tool-bcg.bwe.io/editor/promo.php?* // @grant none // @namespace http://tampermonkey.net/ // ==/UserScript== (function() { class AutoCheck { constructor(scope,title,checkBoxes,originalCurrency) { this.scope = scope; this.title = title; this.matchRes = ''; this.checkBoxes = checkBoxes; this.len = checkBoxes.length; this.originalCurrency = originalCurrency; this.sitewide = false;//辅助clearance this.sitewideChecked = this.percentChecked = this.moneyChecked = this.clearanceChecked = this.fsChecked = this.rebateChecked =this.rewardChecked = this.ftChecked = this.fdChecked =this.fgChecked= this.fsamChecked = this.bngnChecked = this.fromChecked = false; this.lastCurrency = ''; this.lastNumber = ''; this.initScopeCheck(); this.initPromoCheck(); } initScopeCheck() { this.scope[2].checked = true; this.sitewideCheck(); } sitewideCheck() { let s = this.title.value; if(!s)return; //|\d+%?\s(\w+\s)+\D+\s?\d+\+?(\s(?!on)|$|,) this.matchRes = s.match(/ on \D+\s?\d+\+?|sitewide|site wide|storewide|store wide|(whole|entire) (site|store)|everything|(all|every|each|any|your|all of your|entire|one|\d+) (order(s?)|next order|purchase(s?)|next purchase|product(s?)|merchandise|item(s?)|brand(s?))|(((when (spend|spending|you spend)|with (order(s?)|purchase(s?)) of) \D+\s?\d+\+?)|with \D+\d+\+?(\s(order(s?)|purchase(s?)))+)($|\s(?!on))/gi); if(this.matchRes===null) { this.sitewideChecked = false; this.scope[0].checked = false; this.scope[2].checked = true; } else { if(!this.sitewideChecked) { this.sitewideChecked = true; this.scope[0].checked = true; this.checkBoxes[3].checked = false; } } } promoDetailCheck(index,regRule,flag,FnSuccess=function(){},FnFail=function(){},specialCheck=false) { let s = this.title.value; if(!s)return; this.matchRes = s.match(regRule); switch(specialCheck) { case 1: if(this.matchRes===null) { this.checkBoxes[index].checked = false; FnFail(); } else { FnSuccess(); } break; default: if(this.matchRes===null) { flag = false; this.checkBoxes[index].checked = false; FnFail(); } else { if(!flag) { flag = true; this.checkBoxes[index].checked = true; FnSuccess(); } } break; } } fsCheck() { let regRule = /((free|complimentary)+(.*)?(shipp|shipment|fs|s&h|delivery|postage|p&p|click)|((\$|€|£|Rs|RS\.|¥|₦|CHF|USD|CAD|GBP|POUND|RMB|AUD|INR|EUR|US$|CA$|AU$)\s?0 ship))/gi; this.promoDetailCheck(0,regRule,this.fsChecked); } getCurrency(currency) { switch(currency) { case '$': case 'usd': case 'cad': case 'aud': case 'us$': case 'ca$': case 'au$': currency = 'dollar'; break; case '£': case 'gbp': case 'pound': currency = 'pound'; break; case '€': case 'eur': currency = 'euro'; break; case 'rmb': case '¥': case 'cny': currency = 'rmb'; break; case 'rs': case 'inr': case 'rs.': currency = 'rupee'; break; case '₦': currency = 'naira'; break; case 'chf': currency = 'chf'; break; } return currency; } moneyCheck() { let regRule = /(free|save|get|enjoy)?((\$|€|£|Rs|RS\.|¥|₦|CHF|USD|CAD|GBP|POUND|RMB|AUD|INR|EUR|US$|CA$|AU$)\s?)?(\d+|\d+\.\d+|(\d{1,3},)?\d{1,3},\d{3})\s?(\$|€|£|Rs|RS\.|¥|₦|CHF|USD|CAD|GBP|POUND|RMB|AUD|INR|EUR|US$|CA$|AU$)?\s(for|on|off|discount|discounts|saving|savings|(\w+\s)+(gift card|gift certificate|voucher|gift voucher))\s?/gi; this.promoDetailCheck(1,regRule,this.moneyChecked,()=>{ let currency = (RegExp.$3||RegExp.$6).toLowerCase(); this.checkBoxes[1].parentElement.nextElementSibling.value = this.getCurrency(currency); this.checkBoxes[1].parentElement.nextElementSibling.nextElementSibling.value = RegExp.$4; },()=>{ this.checkBoxes[1].parentElement.nextElementSibling.value = this.originalCurrency; this.checkBoxes[1].parentElement.nextElementSibling.nextElementSibling.value =''; }); } percentCheck() { let regRule = /((save|get|enjoy)\s)?(\d+|\d+\.\d+)%\s(off|discount|discounts|saving|savings|on|for)\s?/gi; this.promoDetailCheck(2,regRule,this.percentChecked,()=>{ this.checkBoxes[2].parentElement.nextElementSibling.value = RegExp.$3; },()=>{ this.checkBoxes[2].parentElement.nextElementSibling.value = ''; }); } clearanceCheck() { this.sitewide = document.querySelector('input[value=SITE_WIDE]').checked; if(this.sitewide)return; let regRule = /\s?(clearan|closeout|sale|reduced)\s?/gi; this.promoDetailCheck(3,regRule,this.clearanceChecked); } bngnCheck() { let regRule = /buy one,? get one free|bogof|bogo fr|(^\d+|\s\d+) for \d+|(^\d+|\s\d+) for the price of \d+|buy \d+\s?,? get \d+ fr/gi; this.promoDetailCheck(4,regRule,this.bngnChecked); } fgCheck() { let regRule = /\s?free\s(gift|gifts)?(?!shipping|ship|shipment|delivery|click|download|trial|(\w+\s)*sample|\D+\s?\d+\+?\s(\w+\s)+(gift card|gift certificate|voucher|gift voucher))/gi; this.promoDetailCheck(5,regRule,this.fgChecked,()=>{ this.checkBoxes[5].checked = true; },function(){},true); } fsamCheck() { let regRule = /\s?free\s(\w+\s)*sample/gi; this.promoDetailCheck(6,regRule,this.fgChecked,()=>{ this.checkBoxes[6].checked = true; },function(){},true); } fdCheck() { let regRule = /(free)+(.*)?\sdownload/gi; this.promoDetailCheck(7,regRule,this.fdChecked); } ftCheck() { let regRule = /(free)+(.*)?\strial/gi; this.promoDetailCheck(8,regRule,this.ftChecked); } rebateCheck() { let regRule = /\srebate(\s|$)/gi; this.promoDetailCheck(9,regRule,this.rebateChecked); } rewardCheck() { let regRule = /\s(reward|rewards|bonus|cashback|cash back)(\s|$)/gi; this.promoDetailCheck(10,regRule,this.rewardChecked); } otherCheck() { let s = this.title.value; if(!s) { this.checkBoxes[11].checked = false; return; } let isAnyoneChecked = false; for(let i=0; i<this.len; i++) { if(i===11)continue; if(this.checkBoxes[i].checked) { isAnyoneChecked = true; this.checkBoxes[11].checked = false; break; } } if(!isAnyoneChecked) { this.checkBoxes[11].checked = true; } } fromCheck() { let regRule = /\s*(from|(start|starting|starts)\s(from|at)|as low as|low to)\s(([^0-9\s]+)\s?(\d+|\d+\.\d+|(\d{1,3},)?\d{1,3},\d{3})(\s|$)|(\d+|\d+\.\d+|(\d{1,3},)?\d{1,3},\d{3})\s?([^0-9\s]+)(\s|$))/gi; this.promoDetailCheck(12,regRule,this.fromChecked,()=>{ let currentCurrency = (RegExp.$5||RegExp.$11).toLowerCase(); let currentNumber = RegExp.$6||RegExp.$9; this.checkBoxes[12].checked = true; this.checkBoxes[12].parentElement.nextElementSibling.value = this.getCurrency(currentCurrency); this.checkBoxes[12].parentElement.nextElementSibling.nextElementSibling.value = currentNumber; },()=>{ this.checkBoxes[12].parentElement.nextElementSibling.value = this.originalCurrency; this.checkBoxes[12].parentElement.nextElementSibling.nextElementSibling.value = ''; },true); } initPromoCheck() { this.percentCheck(); this.moneyCheck(); this.clearanceCheck(); this.bngnCheck(); this.fgCheck(); this.fsamCheck(); this.fsCheck(); this.fdCheck(); this.ftCheck(); this.rebateCheck(); this.rewardCheck(); this.fromCheck(); this.otherCheck(); this.sitewideCheck(); } bindEvent() { this.title.addEventListener('input',(e)=>{ this.initPromoCheck(); },false); } exec() { this.bindEvent(); } } let oAutoCheck = new AutoCheck(document.querySelectorAll("input[name='scope_apply']"),document.querySelector('#title'),document.querySelectorAll('#PromotionDetail > div > p > span > input[type=checkbox]'),document.querySelector("[name='money_type[money]']").value); oAutoCheck.exec(); document.querySelector('input[value=SITE_WIDE]').addEventListener('click',function(){ document.querySelector('input[value=sale_clearance]').checked = false; },false); })();