TabacooRecorder

Record your tabacoo order

目前為 2016-12-14 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         TabacooRecorder
// @namespace    https://greasyfork.org/users/86741
// @author       huage
// @description  Record your tabacoo order
// @include      http://gdgz.xinshangmeng.com*
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @version      0.1
// @run-at       document-end
// @license      MIT
// ==/UserScript==

/****************************************
######## version 20161214 #########
保存在新商盟的最近一次下单记录
****************************************/
console.log("华哥的记录保存脚本开始执行!");

//注册菜单
GM_registerMenuCommand('保存输入',Save);
GM_registerMenuCommand('读取记录',Load);
GM_registerMenuCommand('控制台显示记录',ShowInConsole);
console.log('脚本菜单注册成功');

//全局变量,常量
var recordJson={}; //记录json
var _lastRecord='lastRecord'; //记录最后一次输入的数据名,_开头表示常量

//保存输入
function Save(){
  console.log('开始保存输入');
  for(var i=1;i<1024;i++){
    id='sort_'+i;
    li=document.getElementById(id);
    if(!li){
      break;
    }
    num=li.getElementsByTagName('input')[1].value;
    if(num>0){
      recordJson[id]=num;
    }
  }
  newRecord=JSON.stringify(recordJson);
  GM_setValue(_lastRecord,newRecord);
  console.log('保存输入成功!保存的json是:');
  console.log(newRecord);
}

//读取输入
function Load(){
  alert('注意!读取记录基于上次的网页编排\n,如编排被改变可能引发错误,请仔细核对!');
  console.log('开始读取输入');
  record=JSON.parse(GM_getValue(_lastRecord));
  console.log(record);
  for(var id in record){
    li=document.getElementById(id);
    li.getElementsByTagName('input')[1].value=record[id];
  }
  console.log('读取输入成功');
}

//控制台查看保存记录
function ShowInConsole(){
  console.log('控制台显示保存记录:');
  record=GM_getValue(_lastRecord);
  console.log(record);
}