Skip to content

Instantly share code, notes, and snippets.

@champierre
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save champierre/93138129e49ccc041998 to your computer and use it in GitHub Desktop.
Save champierre/93138129e49ccc041998 to your computer and use it in GitHub Desktop.
Sample Greasemonkey script that retrieves order info from BASE admin page
// ==UserScript==
// @name Base Order Info Retriever Sample
// @namespace http://tsukurusha.com/
// @version 1.0
// @description Sample Greasemonkey script that retrieves order info from BASE admin page
// @author Junya Ishihara
// @match http://*/*
// @grant GM_setValue
// @include https://admin.thebase.in/*
// @require http://code.jquery.com/jquery-2.1.4.min.js
// ==/UserScript==
function saveBaseOrderInfo() {
var product = $("#OrderDetailForm td:eq(3) a").html();
var fullName = $('#orderInfo section:eq(1) tr:eq(0) td:eq(0)').html();
var lastName = fullName.split(' ')[0];
var firstName = fullName.split(' ')[1];
var zipCode = $('#orderInfo section:eq(1) tr:eq(1) td:eq(0)').html().replace(/[〒-]/g, '');
var fullAddress = $('#orderInfo section:eq(1) tr:eq(2) td:eq(0)').html().replace(/^\s+/g, '').replace(/<br>\s+/g, '').replace(/\s+$/g, '');
var prefecture = fullAddress.split(' ')[0];
var address = fullAddress.split(' ')[1];
var tel = $('#orderInfo section:eq(1) tr:eq(3) td:eq(0)').html();
GM_setValue("product", product);
GM_setValue("lastName", lastName);
GM_setValue("firstName", firstName);
GM_setValue("zipCode", zipCode);
GM_setValue("prefecture", prefecture);
GM_setValue("address", address);
GM_setValue("tel", tel);
alert("product: " + product + "\nlastName: " + lastName + "\nfirstName: " + firstName + "\nzipCode: " + zipCode + "\nprefecture:" + prefecture + "\naddress:" + address + "\ntel: " + tel + "\n\nを取り込みました。");
}
if (location.pathname.startsWith("/order/detail/")) {
var importButton = document.createElement("button");
importButton.href = "javascript:void(0);";
importButton.style.marginLeft = "5px";
importButton.addEventListener("click", saveBaseOrderInfo, false);
importButton.innerHTML = "購入者情報取り込み";
$("#orderInfo section:eq(1) .caption").append(importButton);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment