Created
July 25, 2017 08:32
-
-
Save x3388638/95e31b6b530da1e6c78b6d057c2fd173 to your computer and use it in GitHub Desktop.
便當開團及時通知
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name din.user.js | |
// @namespace yy.dinLunch | |
// @version 0.1 | |
// @description din ban don | |
// @author Y.Y. | |
// @match http://cxlsvr60/test_area/9003/90033/OrderSystem/dinbandon/LUNCH_HOME.ASP | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
/** | |
* include jQuery | |
*/ | |
var script = document.createElement('script'); | |
script.src = 'https://code.jquery.com/jquery-3.2.1.min.js'; | |
script.type = "text/javascript"; | |
script.onload = function () { | |
jQuery.noConflict(); | |
Lunch.init(); | |
}; | |
document.body.appendChild(script); | |
/** | |
* main | |
*/ | |
var Lunch = (function () { | |
let $; | |
/** | |
* private variable | |
*/ | |
var _interval; | |
var _cycle = 10 * 1000; | |
var _food1; | |
var _food2; | |
/** | |
* init | |
*/ | |
function _init() { | |
$ = jQuery; | |
} | |
function _initUI() { | |
$('head').after(` | |
<button id="din">監控便當~~~</button> | |
<style> | |
#din { | |
position: fixed; | |
top: 3px; | |
right: 10px; | |
color: #fff; | |
padding: 8px; | |
background-color: #337ab7; | |
border: 1px solid #2e6da4 !important; | |
border-radius: 10px; | |
cursor: pointer; | |
transition: all .25s; | |
} | |
#din:hover { | |
background-color: #204d74; | |
border-color: 122b40; | |
} | |
#din.dinning { | |
background-color: #d9534f; | |
border-color: #d43f3a; | |
} | |
#din.dinning:hover { | |
background-color: #c9302c; | |
border-color: #ac2925; | |
} | |
</style> | |
`); | |
} | |
/** | |
* bind event | |
*/ | |
function _bindEvent() { | |
$('#din').on('click', _handleClick); | |
} | |
/** | |
* handler | |
*/ | |
function _handleClick() { | |
if ($(this).hasClass('dinning')) { | |
_resetBtn(); | |
return; | |
} | |
$(this).addClass('dinning').text('監控便當中...'); | |
_interval = setInterval(function () { | |
_getPage().done(_parseLunch); | |
}, _cycle); | |
} | |
/** | |
* private method | |
*/ | |
function _getPage() { | |
return $.get('http://cxlsvr60/test_area/9003/90033/OrderSystem/dinbandon/LUNCH_BODY.ASP'); | |
} | |
function _parseLunch(html) { | |
var $wrap = $('<div>'); | |
$wrap.append(html); | |
var content = $wrap.find('h2 form table tbody tr td b font[color="darkblue"]').text(); | |
var arr = content.split('\n'); | |
var food1 = arr[2].trim(); | |
var food2 = arr[4].trim(); | |
if (food1 != '今日尚未開張' && food2 != '今日尚未開張') { | |
_food1 = food1; | |
_food2 = food2; | |
_resetBtn(); | |
alert(`訂便當囉: \n葷: ${_food1}\n素: ${_food2}`); | |
location.reload(); | |
} | |
} | |
function _resetBtn() { | |
$('#din').removeClass('dinning').text('監控便當~~~'); | |
clearInterval(_interval); | |
} | |
/** | |
* public method | |
*/ | |
function init() { | |
_init(); | |
_initUI(); | |
_bindEvent(); | |
} | |
return { | |
init | |
}; | |
})(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment