Skip to content

Instantly share code, notes, and snippets.

@doylecnn
Last active June 27, 2017 10:52
Show Gist options
  • Save doylecnn/90034d7a1d946d09cbc91af4ef212ae3 to your computer and use it in GitHub Desktop.
Save doylecnn/90034d7a1d946d09cbc91af4ef212ae3 to your computer and use it in GitHub Desktop.
soitec web ui change
// ==UserScript==
// @name soitec date change
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://secoaa.soitec.net/Monitoring
// @grant none
// @include https://secoaa.soitec.net/Monitoring*
// ==/UserScript==
var dateFormat = function () {
var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
timezoneClip = /[^-+\dA-Z]/g,
pad = function (val, len) {
val = String(val);
len = len || 2;
while (val.length < len) val = "0" + val;
return val;
};
// Regexes and supporting functions are cached through closure
return function (date, mask, utc) {
var dF = dateFormat;
// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
mask = date;
date = undefined;
}
// Passing date through Date applies Date.parse, if necessary
date = date ? new Date(date) : new Date();
if (isNaN(date)) throw SyntaxError("invalid date");
mask = String(dF.masks[mask] || mask || dF.masks["default"]);
// Allow setting the utc argument via the mask
if (mask.slice(0, 4) == "UTC:") {
mask = mask.slice(4);
utc = true;
}
var _ = utc ? "getUTC" : "get",
d = date[_ + "Date"](),
D = date[_ + "Day"](),
M = date[_ + "Month"](),
y = date[_ + "FullYear"](),
H = date[_ + "Hours"](),
m = date[_ + "Minutes"](),
s = date[_ + "Seconds"](),
L = date[_ + "Milliseconds"](),
o = utc ? 0 : date.getTimezoneOffset(),
flags = {
d: d,
dd: pad(d),
ddd: dF.i18n.dayNames[D],
dddd: dF.i18n.dayNames[D + 7],
M: M + 1,
MM: pad(M + 1),
MMM: dF.i18n.monthNames[M],
MMMM: dF.i18n.monthNames[M + 12],
yy: String(y).slice(2),
yyyy: y,
h: H % 12 || 12,
hh: pad(H % 12 || 12),
H: H,
HH: pad(H),
m: m,
mm: pad(m),
s: s,
ss: pad(s),
l: pad(L, 3),
L: pad(L > 99 ? Math.round(L / 10) : L),
t: H < 12 ? "a" : "p",
tt: H < 12 ? "am" : "pm",
T: H < 12 ? "A" : "P",
TT: H < 12 ? "AM" : "PM",
Z: utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
o: (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
S: ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
};
return mask.replace(token, function ($0) {
return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
});
};
}();
// Some common format strings
dateFormat.masks = {
"default": "ddd MMM dd yyyy HH:mm:ss",
shortDate: "m/d/yy",
mediumDate: "MMM d, yyyy",
longDate: "MMMM d, yyyy",
fullDate: "dddd, MMMM d, yyyy",
shortTime: "h:mm TT",
mediumTime: "h:mm:ss TT",
longTime: "h:mm:ss TT Z",
isoDate: "yyyy-MM-dd",
isoTime: "HH:mm:ss",
isoDateTime: "yyyy-MM-dd'T'HH:mm:ss",
isoUtcDateTime: "UTC:yyyy-MM-dd'T'HH:mm:ss'Z'"
};
// Internationalization strings
dateFormat.i18n = {
dayNames: [
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
],
monthNames: [
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
]
};
// For convenience...
Date.prototype.format = function (mask, utc) {
return dateFormat(this, mask, utc);
};
class LotInfo {
constructor(page, row, lotid, status, date, part, error) {
this.page = page;
this.row = row+1;
this.lotid = lotid;
this.status = status;
this.date = date;
this.part = part;
this.error = error;
}
toHtml(){
var lotCell = "<td><a href=\"/Monitoring?pageGrid=" + this.page + "&selectedRowGrid=" + this.row + "\" title=\"" + this.status + "\"";
if(this.status === "Failed"){
lotCell += " class=\"redCell\"";
}else{
lotCell += " class=\"greenCell\"";
}
lotCell += ">" + this.lotid + "</a></td>";
var dateCell = "<td>" + dateFormat(new Date(this.date+"+0000"),"yyyy-MM-dd HH:mm:ss Z") + "</td>";
var partCell = "<td><span style=\"font-weight:bold;";
switch (this.part) {
case "C1099-056-01":
partCell += "\">[P0D:NXP]";
break;
case "C12944-008-01":
partCell += "\">[P0D:SSMC]";
break;
case "C12002-025-01":
partCell += "\">[TR]";
break;
default:
partCell += "color:red\">[UNKNOW]";
break;
}
partCell += "</span>" + this.part + "</td>";
var errorCell = "<td";
if(this.error.length>0){
errorCell += " class=\"redCell\"";
}
errorCell += ">" + this.error + "</td>";
var rst = "";
if(this.row % 2 === 0){
rst = "<tr>";
}else{
rst = "<tr class=\"alt\">";
}
rst += lotCell + dateCell + partCell + errorCell + "</tr>";
return rst;
}
}
function main(){
'use strict';
var thead = "<thead><tr class=\"th\"><th scope=\"col\"><a href=\"/Monitoring?sort=Lot&amp;sortdir=ASC\">Lot</a></th><th scope=\"col\"><a href=\"/Monitoring?sort=HoldDate&amp;sortdir=ASC\">Attempt Date</a></th><th scope=\"col\"><a href=\"/Monitoring?sort=PartCommercial&amp;sortdir=ASC\">PartCommercial</a></th><th scope=\"col\"><a href=\"/Monitoring?sort=HoldReason&amp;sortdir=ASC\">Error Type</a></th></tr></thead>";
var tfoot = "<tfoot><tr><td colspan=\"4\">";
var currentPage = parseInt((location.search.match(/pageGrid=(\d+)/)||'')[1],10)||1;
var pagestart = 1;
var pages = 20;
if (currentPage > pages/2){
pagestart = currentPage - pages/2;
}
if(currentPage>1){
tfoot+="<span><a href=\"/Monitoring?pageGrid="+(currentPage-1)+"\">&lt;</a></span>&nbsp;";
}
for(var i=pagestart;i<=currentPage+pages;i++){
tfoot+="<span><a href=\"/Monitoring?pageGrid="+i+"\">"+i+"</a></span>&nbsp;";
}
tfoot+="<span><a href=\"/Monitoring?pageGrid="+(currentPage+1)+"\">&gt;</a></span></td></tr></tfoot>";
var table = document.createElement("table");
table.setAttribute("class", "table");
table.setAttribute("id", "grid");
table.innerHTML = thead+tfoot;
var rows = $('#grid tbody tr').map(function(i,tr){
var lotid = tr.children[0].innerText.trim();
var status = tr.children[1].innerText.trim();
var date = tr.children[2].innerText.trim().trim();
var part = tr.children[3].innerText.trim();
var error = tr.children[4].innerText.trim();
var lotinfo = new LotInfo(currentPage ,i, lotid, status, date, part, error);
return lotinfo.toHtml();
});
table.innerHTML += "<tbody>"+rows.toArray().join('')+"</tbody>";
$('#grid')[0].setAttribute("style","display:none");
$('#grid')[0].parentNode.insertBefore(table,$('#grid')[0]);
}
(function() {
main();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment