There are 25 previous versions of this script.
the source is over 100KB, syntax highlighting in the browser is too slow
// ==UserScript==
// @name Adds a link to download video for VReel
// @namespace http://userscripts.org/users/76078
// @version 1.10.3
// @description Adds a link to download video for VReel User
// @include http://beta.vreel.net/*
// ==/UserScript==
(function() {
// for update check
const THIS_SCRIPT_NO = '40675';
const THIS_URL = 'http://userscripts.org/scripts/show/'+THIS_SCRIPT_NO;
const THIS_VER = '1.10.3';
const MSGBOX_ID = "USO_USER_SCRIPT_UPDATE_CHECK_"+THIS_SCRIPT_NO
const NO_CHECK = 0;
const EVERY_LOADING = 1;
const ONCE_A_DAY = 2;
const ONCE_A_WEEK = 3;
const ONCE_A_MONTH = 4;
// option of 'Once a week' mode
const ANY_DAY = -1; // on the first loading of a week
const SUNDAY = 0;
const MONDAY = 1;
const TUESDAY = 2;
const WEDNESDAY = 3;
const THURSDAY = 4;
const FRIDAY = 5;
const SATURDAY = 6;
var update_check = {
type: ONCE_A_WEEK,
last_check_date: 0,
specified_day: ANY_DAY,
};
const TEXT_TYPE = 0;
const IMAGE_TYPE = 1;
// for player size
const MIN_WIDTH = 128; // 640/5
const MIN_HEIGHT = 96; // 480/5
const MAX_WIDTH = 2560; // 640*4
const MAX_HEIGHT = 1920; // 480*4
const DEFAULT_PLAYER_WIDTH = 710; //original value is 710
const DEFAULT_PLAYER_HEIGHT = 405; // original value is 405
// for script control
const WAITING = -1;
const NONE = 0;
const SENT_REQUEST = 1;
const RECEIVED_RESPONSE = 2;
const STORED_DATA = 3;
const NOT_RECEIVED = 4;
const MAX_SEND_REQUEST = 10; // up to 10 http request at the same time
const QUEUE_CHECK_INTERVAL = 5*1000; // 5 sec.
const QUEUE_CHECK_INTERVAL_DONE = 10*1000; // 10 sec.
const MAX_WAIT_LIMIT = 120*1000; // 120 sec
const MAX_RETRY = 3; // 3 times
const PROCESSING_THRESHOLD = 20; // up to 20 videos
const MIN_INTERVAL = 3;
const MIN_MAX_SEND = 1;
const MIN_MAX_WAIT = 30;
const MIN_MAX_RETRY = 0;
const MAX_INTERVAL = 60;
const MAX_MAX_SEND = 25;
const MAX_MAX_WAIT = 300;
const MAX_MAX_RETRY = 10;
var current_request_num = 0;
var total_queue_num = 0;
var last_done_num = 0;
var retry_count = 0;
var check_interval = 0;
var queue = new Array(0);
var pidmap = new Array(0);
var button_style = 'color:#FFFFFF;background-color:#008888;font-weight:bold;cursor:pointer;';
// for watch page
var download_url;
var download_url_prev;
var preview_image_url;
var preview_image_url_prev;
// for list page
var need_information = false;
var need_name = false;
var need_length = false;
var need_views = false;
var need_addedDate = false;
var cols_per_row = 0;
// You can customize initial value.
const SETUP_VERSION = 2;
var custom = {
setup_version: 0,
player: { // video panel
autoplay: true, // true or false
auto_resize: false, // true or false
player_height: DEFAULT_PLAYER_HEIGHT, // pixel value
player_width: DEFAULT_PLAYER_WIDTH, // pixel value
min_height: MIN_HEIGHT, // pixel value, minimum height of resizing
min_width: MIN_WIDTH, // pixel value, minimum width of resizing
max_height: 768, // pixel value, maximum height of resizing
max_width: 1024, // pixel value, maximum width of resizing
lock_ratio: true, // true only
fit_aspect_ratio: false, // true or false
top: 'center', // pixel value or 'center'
left: 'center', // pixel value or 'center'
},
extention: '.avi', // '.avi' or '.divx'
list: {
download_link: true,
watch_button: true,
username: true,
duration: true,
resolution: true,
views: true,
added_date: false, // if ne.edgecastcdn.net,it will be needed RefControl etc.
video_size: false, // if ne.edgecastcdn.net,it will be needed RefControl etc. not supported now.
},
watch: {
autoplay: true, // true or false
disp_type: TEXT_TYPE,
bg_color: '#02B4F9',
text_color: '#FFFFFF',
image_url: '',
video_size: false, // if ne.edgecastcdn.net,it will be needed RefControl etc.
added_date: false, // if ne.edgecastcdn.net,it will be needed RefControl etc.
},
queue: {
check_interval: QUEUE_CHECK_INTERVAL,
check_interval_done: QUEUE_CHECK_INTERVAL_DONE,
max_send_request: MAX_SEND_REQUEST,
max_wait_limit: MAX_WAIT_LIMIT,
max_retry: MAX_RETRY,
threshold: PROCESSING_THRESHOLD,
},
};
// for watch pages
var added_box_watch = {
// meta data in watch pages
meta: {
size_id: 'AddsALinkVideoSize',
added_id: 'AddsALinkAddedDate'
},
// for the video download button
// for text type
texttype: {
div_id: 'AddsALinkDownloadBox',
div_styled: '',
anchor_id: 'AddsALinkDownloadURL',
anchor_style: 'margin-left: 10px;'
},
// for image type
imagetype: {
div_id: 'AddsALinkImageDownloadBox',
div_styled: '',
anchor_id: 'AddsALinkImageDownloadURLAnchor',
anchor_style: 'padding: 0pt; margin-left: 10px;',
image_id: 'AddsALinkImageDownloadURLImage',
image_style: ''
},
};
// for open/close a box
var styles = {
open: 'display:inline;',
block_open: 'display:block;',
close: 'display:none;'
};
//// for video list
// added box for the checkbox and the download link
var added_box = {
base: {
id: 'AddsALinkBase_',
style: 'float:left;'
},
download: {
id: 'AddsALinkDownload_',
style: 'color:#02B4F9;font-weight:bold;'
},
meta: {
id: 'AddsALinkMetaBox_',
name_id: 'AddsALinkUsername_',
wait_id: 'AddsALinkMetaWait_',
style: 'color:#00FF00;',
name_style: 'color:#FFFF00;font-weight:bold;',
wait_style: 'color:#FF0000;background-color:#FFFFFF;'
},
watch: {
id: 'AddsALinkWatch_',
style: button_style
}
};
var video_panel = {
box: {
id: 'VideoMovie',
style: 'padding:20px 20px 40px 20px;position:fixed;background-color:rgba(0,0,0,0.9);z-index:200000;display:block;cursor:move;',
close_style: 'display:none;'
},
title: {
id: 'AddsALinkWatchTitle',
style: 'display:block;padding:0px 40px 4px 0px;font-weight:bold;color:#FFFFFF;font-size:14px;text-align:center;height:1em;overflow:hidden;'
},
player: {
id: 'AddsALinkPlayer',
style: 'margin:10px 0px 0px 0px;'
},
download: {
type: 'link', // 'button' or 'link'
id: 'AddsALinkDownloadButton',
style: button_style+'margin-top:10px;padding:2px 4px 2px 4px;float:right;'
},
lock: {
id: 'AddsALinkLockButton',
style: button_style+'position:absolute;top:5px;right:25px;'
},
close: {
id: 'AddsALinkCloseButton',
style: button_style+'position:absolute;top:5px;right:5px;'
},
lock_ratio: {
id: 'AddsALinkLockRatioChkbox',
style: 'height:14px;position:absolute;bottom:30px;left:10px;',
label_style: 'height:14px;position:absolute;bottom:30px;left:30px;color:#FFFFFF;'
},
status_bar: {
id: 'AddsALinkStatusBar',
style: 'height:14px;width:99%;position:absolute;bottom:0px;left:0px;padding:2px;color:#FFFF00;background-color:#202020;'
},
resize: {
id: 'AddsALinkResizeBox',
style: 'height:16px;width:16px;position:absolute;bottom:0px;right:0px;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAIAAACQKrqGAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAB9SURBVHjaYrxy4QQDcQAggJiIUaStbw4kAQKIiRh1jY2NQAZAADERqQ4IAAKIiRh1IQEeQBIggJiIUQdxK0AAMRGjDsIGCCAmItUBAUAAMRGjDuJWgABiIkYdxK0AAcREjDoIGyCAmIhUBwQAAcREjDqIWwECiJH45AIQYACQSUAeiz1vwgAAAABJRU5ErkJggg==");'
}
};
// for setup
const li_style = "padding-left:10px;padding-top:6px;font-size:12px;";
const tab_base_style = "position:absolute;top:40px;text-align:center;height:40px;width:64px;cursor:pointer;z-index:2;-moz-border-radius:3px;";
const tab_style = tab_base_style+"font-weight:normal;border:3px inset buttonface;";
const tab_style_active = tab_base_style+"font-weight:bold;border:3px outset buttonface;border-bottom:3px solid buttonface;";
const setup_box_style = "z-index:1;display:none;";
const setup_box_style_active = "z-index:1;display:block;";
var setup_box = {
base: {
id: 'AddsALinkSetupBox',
style: 'position:fixed;width:450px;color:#000000;background-color:buttonface;border:3px outset buttonface;font-size:14px;padding-top:6px;z-index:200000;',
title_style: 'text-align:center;margin:0 0 5px 0;font-weight:bold;',
tabs_style: 'margin:0 0 20px 0;font-weight:bold;height:40px;',
hr_style: 'border: 0px solid black;border-bottom:1px solid #000000;',
box_style: setup_box_style,
box_style_active: setup_box_style_active,
ul_style: 'list-style:none inside;',
},
tabs: {
list: {
id: 'AddsALinkSetupBoxListTab',
box_id: 'AddsALinkSetupBoxListBox',
style: tab_style+'left:0px;',
style_active: tab_style_active+'left:0px;',
},
video: {
id: 'AddsALinkSetupBoxVideoTab',
box_id: 'AddsALinkSetupBoxVideoBox',
style: tab_style+'left:70px;',
style_active: tab_style_active+'left:70px;',
},
watch: {
id: 'AddsALinkSetupBoxWatchTab',
box_id: 'AddsALinkSetupBoxWatchBox',
style: tab_style+'left:140px;',
style_active: tab_style_active+'left:140px;',
},
script: {
id: 'AddsALinkSetupBoxScriptControlTab',
box_id: 'AddsALinkSetupBoxScriptControlBox',
style: tab_style+'left:210px;',
style_active: tab_style_active+'left:210px;',
},
update: {
id: 'AddsALinkSetupBoxUpdateCheckerTab',
box_id: 'AddsALinkSetupBoxUpdateCheckerBox',
style: tab_style+'left:280px;',
style_active: tab_style_active+'left:280px;',
}
},
watch: {
disp_type_name: 'AddsALinkSetupWatchDispType',
text_type_id: 'AddsALinkSetupWatchDispTypeText',
image_type_id: 'AddsALinkSetupWatchDispTypeImage',
text_color_id: 'AddsALinkSetupWatchTextColor',
bg_color_id: 'AddsALinkSetupWatchBGColor',
image_url_id: 'AddsALinkSetupWatchImageURL',
video_size_id: 'AddsALinkSetupWatchVideoSize',
added_date_id: 'AddsALinkSetupWatchAddedDate',
autoplay_id: 'AddsALinkSetupWatchAutoplay',
disp_type_style: 'margin:5px 0 0 0;',
title_style: 'text-align:center;margin:0 0 5px 0;font-weight:bold;',
ul_style: 'padding-left:20px;padding-top:6px;list-style:none inside;',
text_type_style: li_style+'margin:0 5px 0 10px;cursor:pointer;',
image_type_style: li_style+'margin:0 5px 0 10px;cursor:pointer;',
image_url_style: li_style,
text_color_style: li_style,
bg_color_style: li_style,
video_size_style: li_style,
added_date_style: li_style,
autoplay_style: li_style
},
list: {
download_link_id: 'AddsALinkSetupListDownloadLink',
username_id: 'AddsALinkSetupListUserName',
duration_id: 'AddsALinkSetupListDuration',
resolution_id: 'AddsALinkSetupListResolution',
views_id: 'AddsALinkSetupListViews',
added_date_id: 'AddsALinkSetupListAddedDate',
watch_button_id: 'AddsALinkSetupListWatchButton',
title_style: 'text-align:center;margin:0 0 5px 0;font-weight:bold;',
ul_style: 'padding-left:20px;padding-top:6px;list-style:none inside;',
download_link_style: li_style,
username_style: li_style,
duration_style: li_style,
resolution_style: li_style,
views_style: li_style,
added_date_style: li_style,
watch_button_style: li_style,
},
video: {
autoplay_id: 'AddsALinkSetupVideoPlayerAutoplay',
auto_resize_id: 'AddsALinkSetupVideoPlayerAutoResize',
lock_ratio_id: 'AddsALinkSetupVideoPlayerLockRatio',
fit_aspect_ratio_id: 'AddsALinkSetupVideoPlayerFitAspectRatio',
height_id: 'AddsALinkSetupVideoPlayerHeight',
width_id: 'AddsALinkSetupVideoPlayerWidth',
min_height_id: 'AddsALinkSetupVideoMinResizeHeight',
min_width_id: 'AddsALinkSetupVideoMinResizeWidth',
max_height_id: 'AddsALinkSetupVideoMaxResizeHeight',
max_width_id: 'AddsALinkSetupVideoMaxResizeWidth',
title_style: 'text-align:center;margin:0 0 5px 0;font-weight:bold;',
ul_style: 'padding-left:10px;padding-top:6px;list-style:none inside;',
autoplay_style: li_style,
auto_resize_style: li_style,
lock_ratio_style: li_style,
fit_aspect_ratio_style: "margin-left: 10px;",
height_style: li_style,
width_style: li_style,
min_height_style: li_style,
min_width_style: li_style,
max_height_style: li_style,
max_width_style: li_style
},
script: {
check_interval_id: 'AddsALinkSetupScriptCheckInterval',
check_interval_done_id: 'AddsALinkSetupScriptCheckIntervalDone',
max_send_request_id: 'AddsALinkSetupScriptMaxSendRequest',
max_wait_limit_id: 'AddsALinkSetupScriptMaxWaitLimit',
max_retry_id: 'AddsALinkSetupScriptMaxRetry',
ul_style: 'padding-left:20px;padding-top:6px;list-style:none inside;',
check_interval_style: li_style,
check_interval_done_style: li_style,
max_send_request_style: li_style,
max_wait_limit_style: li_style,
max_retry_style: li_style,
},
update: {
check_now_id: 'AddsALinkSetupCheckNowButton',
check_now_style: 'position:absolute;right:40px;top:100px;margin:10px 0px 10px 100px;cursor:pointer;background-color:buttonface;',
type_name: 'AddsALinkSetupUpdateTypeName',
day_name: 'AddsALinkSetupUpdateDayName',
no_check_id: 'AddsALinkSetupUpdateNoCheck',
every_loading_id: 'AddsALinkSetupUpdateEveryLoading',
once_a_day_id: 'AddsALinkSetupUpdateOnceADay',
once_a_week_id: 'AddsALinkSetupUpdateOnceAWeek',
once_a_month_id: 'AddsALinkSetupUpdateOnceAMonth',
day_box_id: 'AddsALinkSetupUpdateDayBox',
any_day_id: 'AddsALinkSetupUpdateCheckAnyDay',
sunday_id: 'AddsALinkSetupUpdateCheckSunday',
monday_id: 'AddsALinkSetupUpdateCheckMonday',
tuesday_id: 'AddsALinkSetupUpdateCheckTuesday',
wednesday_id: 'AddsALinkSetupUpdateCheckWednesday',
thursday_id: 'AddsALinkSetupUpdateCheckThursday',
friday_id: 'AddsALinkSetupUpdateCheckFriday',
saturday_id: 'AddsALinkSetupUpdateCheckSaturday',
title_style: 'text-align:center;margin:0 0 5px 0;font-weight:bold;',
ul_style: 'padding-left:10px;padding-top:6px;list-style:none inside;',
hr_style: 'border: 0px solid black;border-top:1px solid #000000;',
day_box_style: 'margin-left:10px;padding-bottom:10px;',
li_style: li_style,
},
radio: {
style: 'cursor:pointer;margin-right:6px;margin-left:10px;'
},
checkbox: {
style: 'cursor:pointer;margin-right:10px;margin-left:15px;'
},
textbox: {
style: 'margin-left:10px;margin-right:10px;'
},
button: {
ok_id: 'AddsALinkSetupOKButton',
cancel_id: 'AddsALinkSetupCancelButton',
ok_style: 'margin:10px 0px 10px 100px;cursor:pointer;',
cancel_style: 'margin:10px 0px 10px 100px;cursor:pointer;'
}
};
var watch_page = false;
var add_download_button = false;
const UNKNOWN_PAGE = 0;
const CHANNEL_PAGE = 1;
const PROFILE_PAGE = 2;
const COMMUNITY_PAGE = 3;
const SEARCH_PAGE = 4;
const MANAGE_PAGE = 5;
const TOP_PAGE = 6;
var page_type = UNKNOWN_PAGE;
const TYPE_INSERTED = 0;
const TYPE_MODIFIED = 1;
var listener_query = '';
var listener_type = TYPE_INSERTED;
var anchor_query = '//a[contains(@href,"watch_")]';
var added_query = '..';
var cell_query = '';
var listbox_query = '';
var tab_query = '';
var tab_query_2 = '';
var tabs = new Array();
var listener_box = null;
var listen_disabled = false;
var player_locked = false;
var last_top = 0;
var last_left = 0;
var last_width = 0;
var last_height = 0;
var last_player_width = 0;
var last_player_height = 0;
var aspect_ratio_locked = false;
var aspect_ratio;
const CELL_HEIGHT_AUTO = 0;
const CELL_HEIGHT_CALC = 1;
var cell_calc_type = CELL_HEIGHT_AUTO;
if(window.location.href == 'http://beta.vreel.net/index.php' ||
window.location.href == 'http://beta.vreel.net/') {
if(document.getElementById("search")) {
page_type = SEARCH_PAGE;
} else {
page_type = TOP_PAGE;
}
}
if(window.location.href.indexOf('q=channels') >= 0) {
page_type = CHANNEL_PAGE;
add_download_button = true;
need_name = true;
need_length = true;
need_views = true;
need_addedDate = true;
cols_per_row = 3;
anchor_query = '//div[@id="block"]/a[contains(@href,"watch_")]';
added_query = '..';
listbox_query = '../..';
listener_query = '//div[@id="left-wide"]';
cell_calc_type = CELL_HEIGHT_CALC;
} else
if(window.location.href.indexOf('q=mye') >= 0) {
add_download_button = true;
page_type = MANAGE_PAGE;
need_length = true;
need_addedDate = true;
anchor_query = '//td/a[contains(@href,"watch_")]';
added_query = '../../td[4]';
listbox_query = '';
listener_query = '//div[@id="left-wide"]';
} else
if(window.location.href.indexOf('/profile_') >= 0 ||
window.location.href.indexOf('q=profile') >= 0 ||
window.location.href.indexOf('q=my') >= 0) {
add_download_button = true;
need_length = true;
need_views = true;
need_addedDate = true;
page_type = PROFILE_PAGE;
cols_per_row = 3;
cell_calc_type = CELL_HEIGHT_CALC;
anchor_query = '//div[@id="vid"]/a[contains(@href,"watch_")]';
added_query = '..';
listbox_query = '../..';
tab_query = 'ancestor::div[contains(@class,"ui-tabs-panel")]';
tab_query_2 = '//div[@id="tabs"]/ul[contains(@class,"ui-tabs-nav")]/li/a|//div[@id="tabs"]/div[contains(@class,"ui-tabs-panel")]/a[contains(@class,"mover")]';
listener_query = '//div[@id="left"]';
} else
if(window.location.href.indexOf('q=community&a=show') >= 0) {
add_download_button = true;
page_type = COMMUNITY_PAGE;
need_name = true;
need_views = true;
need_addedDate = true;
anchor_query = '//div[@class="vidzz"]/h2/a[contains(@href,"watch_")]';
added_query = '../..';
listbox_query = '../../..';
listener_query = '//div[@class="left"]';
} else
if(page_type == SEARCH_PAGE ||
window.location.href.indexOf('q=search') >= 0) {
add_download_button = true;
page_type = SEARCH_PAGE;
need_length = true;
anchor_query = '//div[@id="search"]/a[contains(@href,"watch_")]';
added_query = '../div[@id="more"]';
listbox_query = 'ancestor::div[@id="content"]';
listener_query = '//div[@id="left-wide"]';
} else
if(page_type == TOP_PAGE) {
add_download_button = true;
need_name = true;
need_views = true;
need_length = true;
need_addedDate = true;
cell_calc_type = CELL_HEIGHT_CALC;
anchor_query = '//div[@id="block"]/h2/a[contains(@href,"watch_")]';
added_query = '../..';
listbox_query = 'ancestor::div[@id="content"]';
tab_query = 'ancestor::div[contains(@class,"ui-tabs-panel")]';
tab_query_2 = '//div[@id="tabs"]/ul[contains(@class,"ui-tabs-nav")]/li/a|//div[@id="tabs"]/div[contains(@class,"ui-tabs-panel")]/a[contains(@class,"mover")]';
listener_query = '//div[@id="left"]';
} else
if(window.location.href.indexOf('http://beta.vreel.net/watch_') >= 0) {
watch_page = true;
} else {
return;
}
Init();
window.addEventListener(
"load",
function() {
if(tab_query_2) {
var xp = document.evaluate(tab_query_2, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if(xp.snapshotLength) {
for (var i=0; i < xp.snapshotLength; i++) {
tabs.push(xp.snapshotItem(i));
}
for (var i in tabs) {
tabs[i].addEventListener("click",ChangedTab,false);
}
}
}
if(watch_page == true) {
watch_page_proc();
}
if(add_download_button == true) {
if(custom.list.download_link || custom.list.username || custom.list.resolution || custom.list.duration ||
custom.list.video_size || custom.list.added_date) {
need_information = true;
}
list_page_proc();
}
},
false);
function Nop(){}
// for list page
function GetSetupDataListPage(){
custom.list = eval(GM_getValue("list_page", custom.list));
}
function SetSetupDataListPage(){
GM_setValue("list_page", uneval(custom.list));
}
// for video panel
function GetSetupDataVideoPanel(){
custom.player = eval(GM_getValue("player", custom.player));
}
function SetSetupDataVideoPanel(){
GM_setValue("player", uneval(custom.player));
}
// for watch page
function GetSetupDataWatchPage(){
custom.watch = eval(GM_getValue("watch_page", custom.watch));
}
function SetSetupDataWatchPage(){
GM_setValue("watch_page", uneval(custom.watch));
}
// for update check
function GetSetupDataUpdateCheck(){
update_check = eval(GM_getValue("update_check", update_check));
}
function SetSetupDataUpdateCheck(){
GM_setValue("update_check", uneval(update_check));
}
// for script control
function GetSetupDataScriptControl(){
custom.queue = eval(GM_getValue("queue", custom.queue));
}
function SetSetupDataScriptControl(){
GM_setValue("queue", uneval(custom.queue));
}
// others setup date
function GetSetupDataOthers(){
custom.extention = GM_getValue("extention", custom.extention);
}
function SetSetupDataOthers(){
GM_setValue("extention", custom.extention);
}
// setup data version
function GetSetupDataVersion(){
custom.setup_version = GM_getValue("setup_version", custom.setup_version);
if(custom.setup_version < SETUP_VERSION) {
ConvertSetupData();
}
}
function SetSetupDataVersion(){
GM_setValue("setup_version", SETUP_VERSION);
}
// for setup data conversion
function ConvertSetupData(){
if(custom.setup_version == 0) { // old format data
// for list page
custom.list.download_link = GM_getValue("add_download_link", custom.list.download_link);
custom.list.username = GM_getValue("add_username", custom.list.username);
custom.list.resolution = GM_getValue("add_resolution", custom.list.resolution);
custom.list.duration = GM_getValue("add_duration", custom.list.duration);
custom.list.views = GM_getValue("add_views", custom.list.views);
custom.list.video_size = GM_getValue("add_video_size_list", custom.list.video_size);
custom.list.added_date = GM_getValue("add_added_date_list", custom.list.added_date);
custom.list.watch_button = GM_getValue("add_watch_button", custom.list.watch_button);
// for watch page
custom.watch.disp_type = GM_getValue("disp_type", custom.watch.disp_type);
custom.watch.image_url = GM_getValue("image_url", custom.watch.image_url);
custom.watch.text_color = GM_getValue("text_color", custom.watch.text_color);
custom.watch.bg_color = GM_getValue("bg_color", custom.watch.bg_color);
custom.watch.video_size = GM_getValue("add_video_size", custom.watch.video_size);
custom.watch.added_date = GM_getValue("add_added_date", custom.watch.added_date);
custom.watch.autoplay = GM_getValue("autoplay_watch", custom.watch.autoplay);
// for video panel
custom.player.autoplay = GM_getValue("autoplay_list", custom.player.autoplay);
custom.player.auto_resize = GM_getValue("auto_resize", custom.player.auto_resize);
custom.player.min_width = GM_getValue("min_width_list", custom.player.min_width);
custom.player.min_height = GM_getValue("min_height_list", custom.player.min_height);
custom.player.max_width = GM_getValue("max_width_list", custom.player.max_width);
custom.player.max_height = GM_getValue("max_height_list", custom.player.max_height);
custom.player.player_height = GM_getValue("player_height_list", custom.player.player_height);
custom.player.player_width = GM_getValue("player_width_list", custom.player.player_width);
custom.player.lock_ratio = GM_getValue("lock_ratio", custom.player.lock_ratio);
SetSetupDataVersion()
SetSetupDataListPage();
SetSetupDataWatchPage();
SetSetupDataVideoPanel();
SetSetupDataScriptControl();
SetSetupDataOthers();
DeleteOldData(0);
} else
if(custom.setup_version == 1) { // V1 format data
custom.queue = GetOldData("queue", custom.queue, null);
custom.player = GetOldData("player", custom.player, null);
SetV2Data();
SetSetupDataVersion()
SetSetupDataVideoPanel();
SetSetupDataScriptControl();
DeleteOldData(1);
}
}
function GetOldData(key, val, ignores) {
var old_data = eval(GM_getValue(key, val));
for(var i in old_data) {
if(ignores) {
if(ignores.indexOf(i) >= 0) {
continue;
}
}
val[i] = old_data[i];
}
return val;
}
function SetV2Data() {
custom.queue.check_interval = QUEUE_CHECK_INTERVAL;
custom.queue.check_interval_done = QUEUE_CHECK_INTERVAL_DONE;
custom.queue.max_retry = MAX_RETRY;
custom.player.fit_aspect_ratio = false;
}
function DeleteOldData(old_version) {
if(old_version == 0) { // old format data
// for list page
GM_deleteValue("add_download_link");
GM_deleteValue("add_username");
GM_deleteValue("add_duration");
GM_deleteValue("add_resolution");
GM_deleteValue("add_views");
GM_deleteValue("add_added_date_list");
GM_deleteValue("add_video_size_list");
GM_deleteValue("add_watch_button");
// for watch page
GM_deleteValue("disp_type");
GM_deleteValue("text_color");
GM_deleteValue("bg_color");
GM_deleteValue("image_url");
GM_deleteValue("add_video_size");
GM_deleteValue("add_added_date");
GM_deleteValue("autoplay_watch");
// for video panel
GM_deleteValue("autoplay_list");
GM_deleteValue("auto_resize");
GM_deleteValue("lock_ratio");
GM_deleteValue("player_width_list");
GM_deleteValue("player_height_list");
GM_deleteValue("min_width_list");
GM_deleteValue("min_height_list");
GM_deleteValue("max_width_list");
GM_deleteValue("max_height_list");
}
}
// initialize
function Init() {
// get setup data
GetSetupDataVersion();
GetSetupDataListPage();
GetSetupDataVideoPanel();
GetSetupDataWatchPage();
GetSetupDataScriptControl();
GetSetupDataUpdateCheck();
GetSetupDataOthers();
// Add menu
GM_registerMenuCommand( "----Downlaod video from VReel----", Nop);
GM_registerMenuCommand( "Set up this script(VReel)", Setup);
// for update check
UpdateCheck(false);
WatchOver();
}
var listener_nodes = new Array();
function Toggle_Listener(mode) {
if(!listener_query) return;
if(listener_nodes.length == 0) {
var xp = document.evaluate(listener_query, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if(xp.snapshotLength) {
for(var i = 0; i < xp.snapshotLength; i++) {
listener_nodes.push(xp.snapshotItem(i));
}
}
}
for(var i = 0; i < listener_nodes.length; i++) {
var node = listener_nodes[i];
if(mode) {
if(listener_type == TYPE_INSERTED)
node.addEventListener("DOMNodeInserted",NodeInserted,false);
else if(listener_type == TYPE_MODIFIED)
node.addEventListener("DOMSubtreeModified",NodeInserted,false);
} else {
if(listener_type == TYPE_INSERTED)
node.removeEventListener("DOMNodeInserted",NodeInserted,false);
else if(listener_type == TYPE_MODIFIED)
node.removeEventListener("DOMSubtreeModified",NodeInserted,false);
}
}
}
function WatchOver() {
check_interval = custom.queue.check_interval;
if(QueueCheck()) {
QueueControl();
}
setTimeout(WatchOver, check_interval);
}
function QueueCheck() {
var sent = 0;
var received = 0;
var count = 0;
var none = 0;
var done = 0;
var wait = 0;
var now = (new Date()).getTime();
for (var pid in queue) {
count++;
switch(queue[pid].stat) {
case SENT_REQUEST:
if(now - queue[pid].sent_time < custom.queue.max_wait_limit) {
sent++;
} else {
WaitMessage(pid, -1, "Can't get informations");
queue[pid].stat = NOT_RECEIVED;
done++;
}
break;
case RECEIVED_RESPONSE:
received++;
break;
case NONE:
none++;
break;
case STORED_DATA:
done++;
break;
case WAITING:
wait++;
break;
default:
done++;
}
}
total_queue_num = count;
current_request_num = sent;
if(last_done_num != done) {
var work = new Array();
for (var pid in queue) {
var list_box = queue[pid].list_box;
if(queue[pid].list_box) {
if(!queue[pid].list_box_id || work.indexOf(queue[pid].list_box_id) >= 0) {
continue;
}
work.push(queue[pid].list_box_id);
Toggle_Listener(false);
ModifyListBoxHeight(pid);
Toggle_Listener(true);
}
}
}
last_done_num = done;
if(current_request_num < custom.queue.max_send_request) {
if(none > 0) {
return true;
}
if(wait > 0) {
for (var pid in queue) {
if(queue[pid].stat == WAITING) {
queue[pid].stat = NONE;
none++;
wait--;
if(wait > 0 && none >= custom.queue.threshold) {
break;
}
}
}
if(none > 0) {
return true;
}
}
if(total_queue_num > done &&
retry_count < custom.queue.max_retry) {
retry_count++;
for (var pid in queue) {
switch(queue[pid].stat) {
case SENT_REQUEST:
case RECEIVED_RESPONSE:
case NOT_RECEIVED:
queue[pid].stat = NONE;
break;
}
}
return true;
}
}
if(total_queue_num == done && done > 0) {
check_interval = custom.queue.check_interval_done;
retry_count = 0;
} else {
check_interval = custom.queue.check_interval;
}
return false;
}
function QueueControl() {
var sent = current_request_num;
var now = (new Date()).getTime();
var work = new Array();
for (var pid in queue) {
if(sent >= custom.queue.max_send_request) {
break;
}
if(queue[pid].stat == NONE) {
GetVideoInformation(pid);
sent++;
}
}
}
// autoplay for watch page
function auto_play() {
var embed = document.getElementsByTagName("embed");
if(embed) {
var newEmbed = embed[0].cloneNode(true);
newEmbed.setAttribute('autoplay', 'true');
var object = embed[0].parentNode;
object.removeChild(embed[0]);
object.appendChild(newEmbed);
}
}
function ModifyFileName(filename) {
filename = filename.replace(/[\\\/:;\*\?\"<>\|]/g,'_');
if(filename.replace('.', '') == '') {
filename = filename.replace(/\./g, '_');
}
return filename;
}
var header_info = { size: '', added: '' };
// watch_page_proc routine
function watch_page_proc() {
var embed = document.getElementsByTagName("embed");
if(!embed || !embed[0]) {
var parent = document.getElementById("VideoMovie");
if(!parent) {
return; // Probably it is a bug.
}
// Get download URL from anchor tag by NoScript
var i;
var childs = parent.childNodes;
for(i = 0; i < childs.length; i++) {
if(childs[i].nodeName.toLowerCase() == 'a') break;
}
if(i >= childs.length) {
return; // Probably it is a bug.
}
download_url = childs[i].getAttribute('href');
if(download_url.indexOf('/player/') >= 0) {
// URL of the DivX player installer
download_url = '';
}
} else {
// Get download URL from embed tag
download_url = embed[0].getAttribute("src");
preview_image_url = embed[0].getAttribute("previewimage");
var node = document.getElementById("content");
if(node) {
node.addEventListener(
"DOMSubtreeModified",
content_modified,
false);
}
}
if(!download_url) {
return;
}
var xp = document.evaluate('//div[@id="content"]/h1', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var l=xp.snapshotLength;
var title = '';
if(l) {
var node = xp.snapshotItem(0);
title = node.textContent;
}
var color ="color: "+custom.watch.text_color+";";
var bgc ="background-color: "+custom.watch.bg_color+";";
// get nav bar object
var nav = document.getElementById("nav");
// Don't edit following code
var html = '<div id="' + added_box_watch.texttype.div_id + '" style="display:none;">' +
'<a id="' + added_box_watch.texttype.anchor_id + '" href="' + download_url + '" style="' + added_box_watch.texttype.anchor_style + color+bgc+'">DOWNLOAD VIDEO</a>' +
'</div>' +
'<div id="' + added_box_watch.imagetype.div_id + '" style="display:none;">' +
'<a id="' + added_box_watch.imagetype.anchor_id + '" href="' + download_url + '" style="' + added_box_watch.imagetype.anchor_style + '">' +
'<img id="' + added_box_watch.imagetype.image_id + '" border="0" src="' + custom.watch.image_url + '" style="' + added_box_watch.imagetype.image_style + '" />' +
'</a></div>';
// Add DOWNLOAD link after the UPLOAD image in the nav bar
var p = document.createElement('li');
p.innerHTML = html;
xp = document.evaluate('.//a[@id="'+added_box_watch.texttype.anchor_id+'"]|.//a[@id="'+added_box_watch.imagetype.anchor_id+'"]', p, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
l=xp.snapshotLength;
for(i = 0; i < l; i++) {
var node = xp.snapshotItem(i);
node.setAttribute('filename',ModifyFileName(title)+custom.extention);
}
if(nav) {
nav.appendChild(p);
ChangeType();
} else {
window.addEventListener(
"load",
function() {
nav.appendChild(p);
ChangeType();
},
true);
}
GetHeaderInformation();
if(custom.watch.autoplay) {
auto_play();
}
}
function content_modified() {
var embed = document.getElementsByTagName("embed");
if(embed) {
download_url = embed[0].getAttribute("src");
preview_image_url = embed[0].getAttribute("previewimage");
var node = document.getElementById(added_box_watch.texttype.anchor_id);
if(node) {
node.href = download_url;
}
node = document.getElementById(added_box_watch.imagetype.anchor_id);
if(node) {
node.href = download_url;
}
GetHeaderInformation();
}
}
const WATCH_URL = 0;
function buildURL(pid, target, site) {
var url = '';
switch(target) {
case WATCH_URL:
url = 'http://beta.vreel.net/'+pid+'.html';
break;
}
return url;
}
function ChangedTab() {
var href = this.getAttribute('href');
var id = href.match(/#(.*)/)[1];
if(!id) { // Maybe "Prev Page" or "Next Page"
var rel = this.getAttribute('rel');
id = 'fragment-'+rel;
}
var tab = document.getElementById(id);
if(tab) {
Toggle_Listener(false);
for (var pid in queue) {
if(queue[pid].tab_id == id &&
queue[pid].stat == STORED_DATA) {
ModifyParentHeight(pid);
ModifyListBoxHeight(pid);
}
}
Toggle_Listener(true);
}
}
function NodeInserted() {
list_page_proc();
Toggle_Listener(false);
for (var pid in queue) {
ModifyParentHeight(pid);
}
Toggle_Listener(true);
}
function list_page_proc() {
AddVideoInformationInList();
}
function AddVideoInformationInList() {
var xp = document.evaluate(anchor_query, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if(xp.snapshotLength) {
for (var i=0; i < xp.snapshotLength; i++) {
var anchor = xp.snapshotItem(i);
var pid = anchor.href.match(/\/(watch_\d+)\.html/)[1];
if(queue[pid]) {
continue;
}
var base = document.createElement('div');
base.id = added_box.base.id + pid;
base.setAttribute('style',added_box.base.style);
var parent = document.evaluate(added_query, anchor, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
var list_box = null;
var list_box_id = null;
if(listbox_query) {
list_box = document.evaluate(listbox_query, anchor, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if(list_box) list_box_id = list_box.id;
}
var tab = null;
var tab_id = null;
if(tab_query) {
tab = document.evaluate(tab_query, anchor, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if(tab) tab_id = tab.id;
}
Toggle_Listener(false);
parent.appendChild(base);
Toggle_Listener(true);
queue[pid] = {
stat: WAITING,
node: base,
list_box: list_box,
list_box_id: list_box_id,
tab: tab,
tab_id: tab_id,
offsetTop: base.parentNode.offsetTop,
};
}
} else {
Toggle_Listener(true);
if(page_type == SEARCH_PAGE) {
page_type == UNKNOWN_PAGE;
}
}
}
function GetVideoInformation(pid) {
if(!need_information) {
return;
}
var url = buildURL(pid, WATCH_URL);
var infoKeys = [
'video_url',
'user_url',
'username',
'resolution',
'duration',
'views',
'embedCode',
'previewimage_url',
'VideoMovie',
'title',
'video_width',
'video_height'
];
setTimeout(function(){
queue[pid].stat = SENT_REQUEST;
queue[pid].sent_time = (new Date()).getTime();
WaitMessage(pid, 1);
GM_xmlhttpRequest({
method:"GET",
url: url,
headers:{
"User-Agent": "Mozilla/4.0 (compatible; MSIE 6.0; Win32)",
"Accept":"*/*"
},
onerror: function(xhr){
var text = xhr.responseText;
GM_log("Error: "+xhr.status + ': ' + text);
},
onload: function(xhr){
var text = xhr.responseText;
var pid = xhr.finalUrl.match(/(watch_\d+)\.html/)[1];
if(!pid) {
GM_log('finalUrl: ' + xhr.finalUrl);
return;
}
queue[pid].stat = RECEIVED_RESPONSE;
if ( xhr.status != 200 ) { // failed
GM_log(xhr.status + ': ' + text);
WaitMessage(pid, xhr.status);
return;
}
var VideoInfo = ParseSourceXml(text);
for (var i in infoKeys) {
queue[pid][infoKeys[i]] = VideoInfo[infoKeys[i]];
}
queue[pid].stat = STORED_DATA;
WaitMessage(pid, 0);
AddMetaData(pid);
GetHeaderInformationList(pid);
}
});
},0);
}
// Parse source xml
function ParseSourceXml(text) {
var videoInfo = {};
var div = document.createElement('div');
div.innerHTML = text;
var xp = document.evaluate('.//embed', div, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var l=xp.snapshotLength;
if(l) {
var embed = xp.snapshotItem(0);
var video_url = embed.getAttribute('src');
if(!video_url) {
return null;
}
videoInfo['video_url'] = video_url;
var previewimage_url = embed.getAttribute("previewimage");
if(previewimage_url) {
videoInfo['previewimage_url'] = previewimage_url;
}
}
xp = document.evaluate('.//object', div, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
l=xp.snapshotLength;
if(l) {
var object = xp.snapshotItem(0);
videoInfo['embedCode'] = object.innerHTML.match(/\<embed.*?\>/);
} else {
xp = document.evaluate('.//div[@id="VideoMovie"]', div, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if(xp) {
videoInfo['VideoMovie'] = xp.textContent.replace(/\n\s*/g,'');
}
}
xp = document.evaluate('.//div[@id="right-small"]/p/strong', div, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
l=xp.snapshotLength;
for(var i = 0; i < l;i++) {
var p = xp.snapshotItem(i);
var key = p.textContent.match(/(.*)\s:/)[1].toLowerCase();
var val = p.nextSibling.textContent.replace(/^\s/,'');
videoInfo[key] = val;
}
if(/(\d*)x(\d*)/.test(videoInfo['resolution'])) {
videoInfo['video_width'] = RegExp.$1;
videoInfo['video_height'] = RegExp.$2;
} else {
videoInfo['video_width'] = '';
videoInfo['video_height'] = '';
}
xp = document.evaluate('.//div[@id="right-small"]/table/tbody/tr[1]/td/a', div, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
l=xp.snapshotLength;
if(l) {
var user = xp.snapshotItem(0);
var user_url = user.getAttribute('href');
if(user_url) {
videoInfo['user_url'] = user_url;
}
var username = user.textContent;
if(username) {
videoInfo['username'] = username;
}
}
xp = document.evaluate('.//div[@id="content"]/h1', div, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
l=xp.snapshotLength;
if(l) {
var node = xp.snapshotItem(0);
var title = node.textContent;
if(title) {
videoInfo['title'] = title;
}
}
xp = document.evaluate('.//div[@class="bookmark"]/div[1]', div, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
l=xp.snapshotLength;
if(l) {
var node = xp.snapshotItem(0);
var views = node.textContent.match(/Views : (\d*)/)[1];
if(views) {
videoInfo['views'] = views;
}
}
return videoInfo;
}
function CalcHeightChildNodes(parent) {
var height = 0;
var old_height = 0;
var offset = -1;
var childNodes = parent.childNodes;
var ignore_box = [ 'sky' ];
for (var i = 0; i < childNodes.length; i++) {
var child = childNodes[i];
if(child.nodeType != 1) continue;
if(child.tagName.toUpperCase() == 'DIV') {
if(ignore_box.indexOf(child.id) >= 0) {
continue;
}
}
if(child.tagName.toUpperCase() == 'A') {
if(!child.firstChild) continue;
if(child.firstChild.nodeType == 1 &&
page_type != TOP_PAGE &&
child.firstChild.tagName.toUpperCase() == 'IMG') {
child = child.firstChild;
}
}
var padding = 0;
if(document.defaultView) {
var style = document.defaultView.getComputedStyle(child, null);
padding = parseInt(style.getPropertyValue('padding-top')) +
parseInt(style.getPropertyValue('padding-bottom'));
padding += parseInt(style.getPropertyValue('margin-top')) +
parseInt(style.getPropertyValue('margin-bottom'));
}
if(offset == child.offsetTop) {
if(old_height < child.offsetHeight + padding) {
height += child.offsetHeight + padding - old_height;
old_height = child.offsetHeight + padding;
}
continue;
}
offset = child.offsetTop;
height += child.offsetHeight + padding;
old_height = child.offsetHeight + padding;
}
return height;
}
function ModifyListBoxHeight(pid) {
height = CalcHeightChildNodes(queue[pid].list_box);
queue[pid].list_box.style.height = height+'px';
}
function ModifyParentHeight(pid) {
var work = new Array();
var height = 0;
for (var wpid in queue) {
if(queue[wpid].offsetTop == queue[pid].offsetTop) {
if(!queue[wpid].node) continue;
if(!queue[wpid].node.parentNode) continue;
if(queue[pid].list_box_id && queue[wpid].list_box_id) {
if(queue[pid].list_box_id != queue[wpid].list_box_id) continue;
}
work.push(wpid);
// if(queue[wpid].stat != STORED_DATA) {
// continue;
// }
var box = queue[wpid].node.parentNode;
var padding = 0;
if(document.defaultView) {
var style = document.defaultView.getComputedStyle(box, null);
padding = parseInt(style.getPropertyValue('padding-top')) +
parseInt(style.getPropertyValue('padding-bottom'));
padding += parseInt(style.getPropertyValue('margin-top')) +
parseInt(style.getPropertyValue('margin-bottom'));
}
var work_height = CalcHeightChildNodes(box);
if(work_height > height) {
height = work_height;
}
}
}
if(height) {
for (var wpid in work) {
if(cell_calc_type == CELL_HEIGHT_CALC) {
queue[work[wpid]].node.parentNode.style.height = height+'px';
} else {
queue[work[wpid]].node.parentNode.style.height = 'auto';
}
}
}
}
function WaitMessage(pid, mode) {
var id = added_box.meta.wait_id + pid;
var div = document.getElementById(id);
// var xp = document.evaluate('//div[@id="'+id+'"]',document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
// var l=xp.snapshotLength;
// if(l > 0) {
// div = xp.snapshotItem(0);
// }
Toggle_Listener(false);
if(mode == 1) {
if(!div) {
div = document.createElement('div');
div.id = id;
div.innerHTML = 'Wait!';
div.setAttribute('style', added_box.meta.wait_style);
if(queue[pid].node) queue[pid].node.appendChild(div);
}
} else if(mode == 0) {
div = document.getElementById(id);
if(div) {
// queue[pid].node.removeChild(div);
div.parentNode.removeChild(div);
}
} else {
div = document.getElementById(id);
if(div) {
div.innerHTML = 'Error status:'+mode;
}
}
if(mode != 0) {
if(queue[pid].node && queue[pid].node.parentNode) {
var height = div.offsetTop - queue[pid].node.parentNode.offsetTop + queue[pid].node.offsetHeight;
queue[pid].node.parentNode.style.height = height+'px';
}
ModifyParentHeight(pid);
}
Toggle_Listener(true);
}
function AddMetaData(pid) {
if(queue[pid].stat != STORED_DATA) return;
Toggle_Listener(false);
// Add download link
var id = added_box.download.id + pid;
var download = document.getElementById(id);
if(!download) {
download = document.createElement('a');
download.id = id;
download.href = queue[pid]['video_url'];
var filename = ModifyFileName(queue[pid]['title']);
download.setAttribute('title',filename);
download.setAttribute('filename',filename+custom.extention);
download.addEventListener("click", function(e) {
e.preventDefault();
window.location.href = this.href;
return false;
},false);
download.innerHTML = 'Download<br />';
queue[pid].node.appendChild(download);
}
if(custom.list.download_link) {
download.setAttribute('style',added_box.download.style + styles.open);
} else {
download.setAttribute('style',added_box.download.style + styles.close);
}
// Add user name(publisher name)
id = added_box.meta.name_id + pid;
var name = document.getElementById(id);
if(!name) {
name = document.createElement('a');
var href = '/'+queue[pid]['user_url'];
name.innerHTML = queue[pid]['username']+'<br />';
name.id = id;
name.href = href;
queue[pid].node.appendChild(name);
}
if(custom.list.username && need_name == true) {
name.setAttribute('style',added_box.meta.name_style + styles.open);
} else {
name.setAttribute('style',added_box.meta.name_style + styles.close);
}
var info = '';
if(custom.list.duration && need_length) {
info += "Length : "+queue[pid]['duration'] +"<br />";
}
if(custom.list.resolution) {
info += "Resolution : "+queue[pid]['resolution'] +"<br />";
}
if(custom.list.views && need_views) {
info += "Views : "+queue[pid]['views'] +"<br />";
}
if(custom.list.video_size && queue[pid]['size']) {
info += "Size : "+queue[pid]['size'] +"<br />";
}
if(custom.list.added_date && need_addedDate && queue[pid]['addedDate']) {
info += "Added : "+queue[pid]['addedDate'] +"<br />";
}
id = added_box.meta.id + pid;
div = document.getElementById(id);
if(!div) {
div = document.createElement('div');
div.id = id;
queue[pid].node.appendChild(div);
}
div.innerHTML = info;
if(custom.list.duration || custom.list.resolution || custom.list.views || custom.list.video_size || custom.list.added_date) {
div.setAttribute('style',added_box.meta.style + styles.open);
} else {
div.setAttribute('style',added_box.meta.style + styles.close);
}
// Add 'Watch video' button
id = added_box.watch.id + pid;
var watch_button = document.getElementById(id);
if(!watch_button) {
watch_button = document.createElement('input');
watch_button.type = 'button';
watch_button.value = 'Watch video';
watch_button.id = id;
watch_button.setAttribute("pid", pid);
watch_button.addEventListener("click",function(e) {
GetEmbedCode(this.id);
},false);
queue[pid].node.appendChild(watch_button);
}
if(custom.list.watch_button) {
watch_button.setAttribute('style',added_box.watch.style + styles.block_open);
} else {
watch_button.setAttribute('style',added_box.watch.style + styles.close);
}
if(queue[pid].node.parentNode) {
var height = queue[pid].node.offsetTop - queue[pid].node.parentNode.offsetTop + queue[pid].node.offsetHeight + 16; // 16 is adjust
queue[pid].node.parentNode.style.height = height+'px';
}
ModifyParentHeight(pid);
Toggle_Listener(true);
}
// Drag&Drop and Resize for Video Panel
var _startX = 0;
var _startY = 0;
var _offsetLeft = 0;
var _offsetTop = 0;
var _dragObj = null;
var _dragObjStack = new Array();
var _dragDisabled = false;
var _resizeObj = null;
var _resizeBox = null;
var _playerNode = null;
var _playerWidth = 0;
var _playerHeight = 0;
var _padding = new Array(4);
function setDragObject(obj) {
if(obj) {
_dragObjStack.push(_dragObj);
_dragObj = obj;
_dragObj.addEventListener('mousedown', dragStart, false);
} else {
document.removeEventListener("mousedown", dragStart, false);
_dragObj = _dragObjStack.pop();
}
}
function dragStart(e) {
if(_dragDisabled == true) return;
if(!e.rangeParent) return;
if(e.rangeParent.nodeType == 1 && e.rangeParent.tagName == 'INPUT') return;
_startX = e.clientX;
_startY = e.clientY;
_offsetLeft = _dragObj.offsetLeft;
_offsetTop = _dragObj.offsetTop;
document.addEventListener("mousemove", dragGo, true);
document.addEventListener("mouseup", dragStop, true);
e.preventDefault();
}
function dragGo(e) {
e.preventDefault();
_dragObj.style.left = (_offsetLeft + e.clientX - _startX) + "px";
_dragObj.style.top = (_offsetTop + e.clientY - _startY) + "px";
}
function dragStop(e) {
document.removeEventListener("mousemove", dragGo, true);
document.removeEventListener("mouseup", dragStop, true);
}
function setResizeObject(obj, box) {
_resizeObj = obj;
_resizeBox = box;
_padding[0] = parseInt(obj.style.paddingTop);
_padding[1] = parseInt(obj.style.paddingRight);
_padding[2] = parseInt(obj.style.paddingBottom);
_padding[3] = parseInt(obj.style.paddingLeft);
if(_resizeObj && _resizeBox) {
_resizeBox.addEventListener('mousedown', resizeStart, false);
} else {
document.removeEventListener("mousedown", resizeStart, false);
}
}
function resizeStart(e) {
_dragDisabled = true;
_startX = e.clientX;
_startY = e.clientY;
_offsetWidth = _resizeObj.offsetWidth;
_offsetHeight = _resizeObj.offsetHeight;
_playerNode = document.getElementById(video_panel.player.id);
_playerWidth = parseInt(_playerNode.width);
_playerHeight = parseInt(_playerNode.height);
document.addEventListener("mousemove", resizeGo, false);
document.addEventListener("mouseup", resizeStop, false);
e.preventDefault();
}
function resizeGo(e) {
var need_adjust = false;
e.preventDefault();
var dist_width = e.clientX - _startX;
var dist_height = e.clientY - _startY;
if(_playerWidth + dist_width > custom.player.max_width) {
dist_width = custom.player.max_width - _playerWidth;
}
if(_playerWidth + dist_width < custom.player.min_width) {
dist_width = custom.player.min_width - _playerWidth;
}
if(aspect_ratio_locked) {
dist_height = (_playerWidth + dist_width) / aspect_ratio - _playerHeight;
}
if(_playerHeight + dist_height > custom.player.max_height) {
dist_height = custom.player.max_height - _playerHeight;
if(aspect_ratio_locked) {
dist_width = (_playerheight + dist_height) * aspect_ratio - _playerWidth;
}
}
if(_playerHeight + dist_height < custom.player.min_height) {
dist_height = custom.player.min_height - _playerHeight;
if(aspect_ratio_locked) {
dist_width = (_playerheight + dist_height) * aspect_ratio - _playerWidth;
}
}
_playerNode.width = _playerWidth + dist_width;
_playerNode.height = _playerHeight + dist_height;
_resizeObj.style.width = (_offsetWidth + dist_width - _padding[1] - _padding[3]) + "px";
_resizeObj.style.height = (_offsetHeight + dist_height - _padding[0] - _padding[2]) + "px";
MakeStatus(_playerNode);
}
function resizeStop(e) {
document.removeEventListener("mousemove", resizeGo, false);
document.removeEventListener("mouseup", resizeStop, false);
last_width = _resizeObj.offsetWidth - _padding[1] - _padding[3];
last_height = _resizeObj.offsetHeight - _padding[0] - _padding[2];
last_player_width = parseInt(_playerNode.width);
last_player_height = parseInt(_playerNode.height);
_dragDisabled = false;
MakeStatus(_playerNode);
}
function GetWatchBoxPosition() {
var div = document.getElementById(video_panel.box.id);
last_top = div.offsetTop;
last_left = div.offsetLeft;
}
function setEmbedSize(div) {
var embed = document.getElementById(video_panel.player.id);
var pid = embed.getAttribute('pid');
var height = 0;
var width = 0;
var top, left;
var auto_resize = custom.player.auto_resize;
var player_height = parseInt(custom.player.player_height);
var player_width = parseInt(custom.player.player_width);
var ratio = parseInt(queue[pid].video_width) / parseInt(queue[pid].video_height);
if(auto_resize == true &&
queue[pid].video_width && queue[pid].video_height) {
embed.height = queue[pid].video_height;
embed.width = queue[pid].video_width;
if(embed.width > custom.player.max_width) {
embed.width = custom.player.max_width;
}
if(embed.height > custom.player.max_height) {
embed.height = custom.player.max_height;
}
height += parseInt(embed.height);
height += parseInt(embed.offsetTop);
width += parseInt(embed.width);
// width += parseInt(embed.offsetLeft);
} else {
if(player_width) {
embed.width = player_width;
width += parseInt(embed.width);
// width += parseInt(embed.offsetLeft);
}
if(player_height) {
if(custom.player.fit_aspect_ratio && ratio) {
embed.height = embed.width / ratio;
} else {
embed.height = player_height;
}
height += parseInt(embed.height);
height += parseInt(embed.offsetTop);
}
}
aspect_ratio = parseInt(embed.width) / parseInt(embed.height);
if(!player_locked) {
var padding_height = parseInt(div.style.paddingTop)+parseInt(div.style.paddingBottom);
var padding_width = parseInt(div.style.paddingLeft)+parseInt(div.style.paddingRight);
top = custom.player.top;
left = custom.player.left;
if(top == 'center') {
top = (window.innerHeight - height - padding_height) / 2;
if(top < 0) {
top = 0;
}
}
if(left == 'center') {
left = (window.innerWidth - width - padding_width) / 2;
if(left < 0) {
left = 0;
}
}
last_top = top;
last_left = left;
div.style.cursor = 'move';
} else {
top = last_top;
left = last_left;
div.style.cursor = 'auto';
}
div.style.height = height + 'px';
div.style.width = width + 'px';
div.style.top = top + 'px';
div.style.left = left + 'px';
MakeStatus(embed);
}
function WatchVideo(id) {
var pid = document.getElementById(id).getAttribute('pid');
var id = video_panel.box.id;
var div = document.getElementById(id);
var append = false;
var top;
var left;
if(!div) {
div = document.createElement('div');
div.id = id;
append = true;
}
div.innerHTML = queue[pid]['embedCode'];
if(custom.player.autoplay) {
div.firstChild.setAttribute('autoplay','true');
}
div.firstChild.setAttribute('pid',pid);
div.firstChild.setAttribute('id',video_panel.player.id);
div.firstChild.setAttribute('style',video_panel.player.style);
div.setAttribute('style', video_panel.box.style);
if(append == true) {
document.body.appendChild(div);
}
append = false;
id = video_panel.title.id;
var title = document.getElementById(id);
if(!title) {
title = document.createElement('span');
append = true;
}
title.id = id;
title.innerHTML = queue[pid]['title'];
title.setAttribute('style', video_panel.title.style);
if(append == true) {
div.insertBefore(title, div.firstChild);
}
append = false;
id = video_panel.download.id;
var download_button = document.getElementById(id);
if(!download_button) {
if(video_panel.download.type == 'button') {
download_button = document.createElement('input');
download_button.type = 'button';
} else {
download_button = document.createElement('a');
}
download_button.id = id;
append = true;
}
if(video_panel.download.type == 'button') {
download_button.value = 'Download video';
} else {
download_button.href = queue[pid]['video_url'];
download_button.innerHTML = 'Download video';
}
download_button.setAttribute('title',queue[pid]['title']);
download_button.setAttribute('filename',ModifyFileName(queue[pid]['title'])+custom.extention);
download_button.setAttribute('style', video_panel.download.style);
if(append == true) {
div.appendChild(download_button);
download_button.addEventListener("click",function(e) {
e.preventDefault();
DownloadVideo(pid);
},false);
}
aspect_ratio_locked = custom.player.lock_ratio;
id = video_panel.lock_ratio.id;
var lock_ratio_chkbox = document.getElementById(id);
if(!lock_ratio_chkbox) {
var label = document.createElement('span');
label.innerHTML = 'Lock aspect ratio';
label.setAttribute('style', video_panel.lock_ratio.label_style);
div.appendChild(label);
lock_ratio_chkbox = document.createElement('input');
lock_ratio_chkbox.type = 'checkbox';
lock_ratio_chkbox.checked = aspect_ratio_locked;
lock_ratio_chkbox.id = id;
lock_ratio_chkbox.setAttribute('style', video_panel.lock_ratio.style);
div.appendChild(lock_ratio_chkbox);
lock_ratio_chkbox.addEventListener("click",ChangeLockRatio,false);
}
id = video_panel.close.id;
var close_button = document.getElementById(id);
if(!close_button) {
close_button = document.createElement('input');
close_button.type = 'button';
close_button.value = 'X';
close_button.id = id;
close_button.setAttribute('style', video_panel.close.style);
div.appendChild(close_button);
close_button.addEventListener("click",CloseVideoPanel,false);
}
id = video_panel.status_bar.id;
var status_bar = document.getElementById(id);
if(!status_bar) {
status_bar = document.createElement('div');
status_bar.innerHTML = '';
status_bar.id = id;
status_bar.setAttribute('style', video_panel.status_bar.style);
div.appendChild(status_bar);
}
id = video_panel.resize.id;
var resize_box = document.getElementById(id);
if(!resize_box) {
resize_box = document.createElement('div');
resize_box.innerHTML = '';
resize_box.id = id;
resize_box.setAttribute('style', video_panel.resize.style);
resize_box.style.cursor = 'se-resize';
div.appendChild(resize_box);
}
setEmbedSize(div);
setResizeObject(div, resize_box);
id = video_panel.lock.id;
var lock_button = document.getElementById(id);
if(!lock_button) {
lock_button = document.createElement('input');
lock_button.type = 'button';
if(!player_locked) {
lock_button.value = 'Lock';
} else {
lock_button.value = 'Unlock';
}
lock_button.id = id;
lock_button.setAttribute('style', video_panel.lock.style);
div.appendChild(lock_button);
lock_button.addEventListener("click",function(e) {
var div = document.getElementById(video_panel.box.id);
var btn = document.getElementById(video_panel.lock.id);
if(!player_locked) {
player_locked = true;
setDragObject(null);
btn.value = 'Unlock';
GetWatchBoxPosition();
div.style.cursor = 'auto';
} else {
player_locked = false;
setDragObject(div);
btn.value = 'Lock';
div.style.cursor = 'move';
}
},false);
}
if(!player_locked) {
setDragObject(div);
}
if(document.getElementById(setup_box.base.id)) {
Player_Visible(false);
window.alert("The video panel is hidden. Close the setup panel to show it.");
}
}
function MakeStatus(embed) {
var pid = embed.getAttribute('pid');
var status = "Resolution: "+queue[pid].video_width+"x"+queue[pid].video_height;
var ratio = Math.round(queue[pid].video_width/queue[pid].video_height * 1000)/1000;
status += " Ratio: "+ratio;
status += " Player size: "+embed.width+"x"+embed.height;
ratio = Math.round(embed.width/embed.height*1000)/1000;
status += " Ratio: "+ratio;
WriteStatusBar(status);
}
function WriteStatusBar(status) {
var status_bar = document.getElementById(video_panel.status_bar.id);
if(!status_bar) return;
status_bar.innerHTML = status;
}
function DownloadVideo(pid) {
window.location.href = queue[pid]['video_url'];
}
function ChangeLockRatio() {
var node = document.getElementById(video_panel.lock_ratio.id);
if(node) {
aspect_ratio_locked = node.checked;
var embed = document.getElementById(video_panel.player.id);
if(embed) {
aspect_ratio = embed.width / embed.height;
}
}
}
function CloseVideoPanel() {
var id = video_panel.box.id;
var div = document.getElementById(id);
if(div) {
div.setAttribute('style', video_panel.box.close_style);
div.parentNode.removeChild(div); // needs this for autoplay
}
setDragObject(null);
}
function Update_List_Page() {
if(custom.list.download_link || custom.list.username || custom.list.resolution || custom.list.duration ||
custom.list.video_size || custom.list.added_date) {
need_information = true;
}
for (var pid in queue) {
if(queue[pid].stat == STORED_DATA) {
AddMetaData(pid);
}
}
var div = document.getElementById(video_panel.box.id);
if(div) {
setEmbedSize(div);
}
}
function Update_Watch_Page() {
ChangeType();
if(custom.watch.video_size == true) {
document.getElementById(added_box_watch.meta.size_id).setAttribute('style', styles.block_open);
} else {
document.getElementById(added_box_watch.meta.size_id).setAttribute('style', styles.close);
}
if(custom.watch.added_date == true) {
document.getElementById(added_box_watch.meta.added_id).setAttribute('style', styles.block_open);
} else {
document.getElementById(added_box_watch.meta.added_id).setAttribute('style', styles.close);
}
}
// Enable or disable download link
function ChangeType() {
var textlink = document.getElementById(added_box_watch.texttype.div_id).getAttributeNode("style");
var anchorlink = document.getElementById(added_box_watch.texttype.div_id).firstChild.getAttributeNode("style");
var imagelink = document.getElementById(added_box_watch.imagetype.div_id).getAttributeNode("style");
var image_url_link = document.getElementById(added_box_watch.imagetype.image_id);
var color = '';
if(custom.watch.text_color) {
color ="color: "+custom.watch.text_color+";";
}
var bgc = '';
if(custom.watch.bg_color) {
bgc ="background-color: "+custom.watch.bg_color+";";
}
if(custom.watch.disp_type == TEXT_TYPE) { // Text type
imagelink.value = styles.close; // disable image link
textlink.value = styles.open; // enable text link
anchorlink.value = added_box_watch.texttype.anchor_style + color + bgc;
} else { // Image type
textlink.value = styles.close; // disable text link
imagelink.value = styles.open; // enable image link
image_url_link.src = custom.watch.image_url;
}
}
// Execute download
function Download() {
if(!download_url) {
return;
}
window.location.href=download_url;
}
function Center_Position(div) {
var height = div.offsetHeight;
var width = div.offsetWidth;
var top = 0;
var left = 0;
top = (window.innerHeight - height) / 2;
if(top < 0) {
top = 0;
}
left = (window.innerWidth - width) / 2;
if(left < 0) {
left = 0;
}
div.style.top = top + 'px';
div.style.left = left + 'px';
}
function Setup() {
if(document.getElementById(setup_box.base.id)) return;
var list_html = Make_Html_For_List_Page();
var video_html = Make_Html_For_Video_Panel();
var watch_html = Make_Html_For_Watch_Page();
var script_html = Make_Html_For_Script_Control();
var update_html = Make_Html_For_Update_Checker();
var html = ''+
'<div style="'+setup_box.base.title_style+'">Set up</div>' +
'<hr style="'+setup_box.base.hr_style+'" />'+
'<div style="'+setup_box.base.tabs_style+'">' +
'<ul style="'+setup_box.base.ul_style+'">' +
'<li id="'+setup_box.tabs.list.id+'" style="'+setup_box.tabs.list.style_active+'">List<br />page</li>' +
'<li id="'+setup_box.tabs.video.id+'" style="'+setup_box.tabs.video.style+'">Video<br />panel</li>' +
'<li id="'+setup_box.tabs.watch.id+'" style="'+setup_box.tabs.watch.style+'">Watch<br />page</li>' +
'<li id="'+setup_box.tabs.script.id+'" style="'+setup_box.tabs.script.style+'">Script<br />control</li>' +
'<li id="'+setup_box.tabs.update.id+'" style="'+setup_box.tabs.update.style+'">Update<br />checker</li>' +
'</ul>'+
'</div>'+
'<div id="'+setup_box.tabs.list.box_id+'" style="'+setup_box.base.box_style_active+'">' +
list_html +
'</div>'+
'<div id="'+setup_box.tabs.video.box_id+'" style="'+setup_box.base.box_style+'">' +
video_html +
'</div>'+
'<div id="'+setup_box.tabs.watch.box_id+'" style="'+setup_box.base.box_style+'">' +
watch_html +
'</div>'+
'<div id="'+setup_box.tabs.script.box_id+'" style="'+setup_box.base.box_style+'">' +
script_html +
'</div>'+
'<div id="'+setup_box.tabs.update.box_id+'" style="'+setup_box.base.box_style+'">' +
update_html +
'</div>'+
'</div>'+
'';
var base = document.createElement('div');
base.innerHTML = html;
base.id = setup_box.base.id;
base.setAttribute('style', setup_box.base.style);
var ok = document.createElement('input');
ok.type = 'button';
ok.id = setup_box.button.ok_id;
ok.setAttribute('style',setup_box.button.ok_style);
ok.value = 'OK';
var cancel = document.createElement('input');
cancel.type = 'button';
cancel.id = setup_box.button.cancel_id;
cancel.setAttribute('style',setup_box.button.cancel_style);
cancel.value = 'Cancel';
var check_now = document.createElement('input');
check_now.type = 'button';
check_now.id = setup_box.update.check_now_id;
check_now.setAttribute('style',setup_box.update.check_now_style);
check_now.value = 'Check now';
ok.addEventListener("click",Save_Setup_Information,false);
cancel.addEventListener("click",Close_Box,false);
check_now.addEventListener("click",Update_Check_Force,false);
base.appendChild(ok);
base.appendChild(cancel);
document.body.appendChild(base);
var update_box = document.getElementById(setup_box.tabs.update.box_id);
update_box.appendChild(check_now);
var list_tab = document.getElementById(setup_box.tabs.list.id);
var video_tab = document.getElementById(setup_box.tabs.video.id);
var watch_tab = document.getElementById(setup_box.tabs.watch.id);
var script_tab = document.getElementById(setup_box.tabs.script.id);
var update_tab = document.getElementById(setup_box.tabs.update.id);
list_tab.setAttribute('stat', 'on');
video_tab.setAttribute('stat', 'off');
watch_tab.setAttribute('stat', 'off');
script_tab.setAttribute('stat', 'off');
update_tab.setAttribute('stat', 'off');
list_tab.addEventListener("click", function(e) {TabClicked(this.id);}, false);
video_tab.addEventListener("click", function(e) {TabClicked(this.id);}, false);
watch_tab.addEventListener("click", function(e) {TabClicked(this.id);}, false);
script_tab.addEventListener("click", function(e) {TabClicked(this.id);}, false);
update_tab.addEventListener("click", function(e) {TabClicked(this.id);}, false);
Setup_List_Page();
Setup_Video_Panel();
Setup_Watch_Page();
Setup_Script_Control();
Setup_Update_Check();
Center_Position(base);
Player_Visible(false);
base.style.cursor = 'move';
setDragObject(base);
}
function TabClicked(id) {
var node = document.getElementById(id);
if(node.getAttribute('stat') == 'on') {
return;
}
var on_tab;
var clicked_tab;
for (var i in setup_box.tabs) {
var tab = document.getElementById(setup_box.tabs[i].id);
if(tab.getAttribute('stat') == 'on') {
on_tab = setup_box.tabs[i];
}
if(id == setup_box.tabs[i].id) {
clicked_tab = setup_box.tabs[i];
}
}
ToggleTab(clicked_tab);
ToggleTab(on_tab);
}
function ToggleTab(param) {
var node = document.getElementById(param.id);
var box_node = document.getElementById(param.box_id);
if(node.getAttribute('stat') == 'on') {
node.setAttribute('stat','off');
node.setAttribute('style',param.style);
box_node.style.display = 'none';
} else {
node.setAttribute('stat','on');
node.setAttribute('style',param.style_active);
box_node.style.display = 'block';
}
}
function Save_Setup_Information() {
if(Check_Options_List_Page() == false) {
alert("The setting of List page is invalid");
return false;
}
if(Check_Options_Video_Panel() == false) {
alert("The setting of Video panel is invalid");
return false;
}
if(Check_Options_Watch_Page() == false) {
alert("The setting of Watch page is invalid");
return false;
}
if(Check_Options_Script_Control() == false) {
alert("The setting of Script control is invalid");
return false;
}
if(Check_Options_Update_Checker() == false) {
alert("The setting of Update checker is invalid");
return false;
}
SetSetupDataVersion();
Save_Options_List_Page();
Save_Options_Video_Panel();
Save_Options_Watch_Page();
Save_Options_Script_Control();
Save_Options_Update_Checker();
Save_Options_Others();
Close_Box();
if(watch_page == true) {
Update_Watch_Page();
} else {
Update_List_Page();
}
}
function Make_Html_For_List_Page() {
var html = ''+
'<ul style="'+setup_box.list.ul_style+'"><b>About adding link and button</b><br />' +
'<li style="'+setup_box.list.download_link_style+'"><input type="checkbox" id="'+setup_box.list.download_link_id+'">Download link</li>' +
'<li style="'+setup_box.list.watch_button_style+'"><input type="checkbox" id="'+setup_box.list.watch_button_id+'">Watch video button</li>' +
'</ul>'+
'<br />'+
'<ul style="'+setup_box.list.ul_style+'"><b>About adding video informations</b><br />' +
'<li style="'+setup_box.list.username_style+'"><input type="checkbox" id="'+setup_box.list.username_id+'">User name</li>' +
'<li style="'+setup_box.list.duration_style+'"><input type="checkbox" id="'+setup_box.list.duration_id+'">Length</li>' +
'<li style="'+setup_box.list.resolution_style+'"><input type="checkbox" id="'+setup_box.list.resolution_id+'">Resolution</li>' +
'<li style="'+setup_box.list.views_style+'"><input type="checkbox" id="'+setup_box.list.views_id+'">Views</li>' +
'<li style="'+setup_box.list.added_date_style+'"><input type="checkbox" id="'+setup_box.list.added_date_id+'">Added date</li>' +
'</ul>'+
'';
return html;
}
function Setup_List_Page() {
var node = document.getElementById(setup_box.list.download_link_id);
node.setAttribute('style',setup_box.checkbox.style);
node.checked = custom.list.download_link;
node = document.getElementById(setup_box.list.username_id);
node.setAttribute('style',setup_box.checkbox.style);
node.checked = custom.list.username;
node = document.getElementById(setup_box.list.duration_id);
node.setAttribute('style',setup_box.checkbox.style);
node.checked = custom.list.duration;
node = document.getElementById(setup_box.list.resolution_id);
node.setAttribute('style',setup_box.checkbox.style);
node.checked = custom.list.resolution;
node = document.getElementById(setup_box.list.views_id);
node.setAttribute('style',setup_box.checkbox.style);
node.checked = custom.list.views;
node = document.getElementById(setup_box.list.added_date_id);
node.setAttribute('style',setup_box.checkbox.style);
node.checked = custom.list.added_date;
node = document.getElementById(setup_box.list.watch_button_id);
node.setAttribute('style',setup_box.checkbox.style);
node.checked = custom.list.watch_button;
}
function Check_Options_List_Page() {
return true;
}
function Save_Options_List_Page() {
custom.list.download_link = document.getElementById(setup_box.list.download_link_id).checked;
custom.list.username = document.getElementById(setup_box.list.username_id).checked;
custom.list.duration = document.getElementById(setup_box.list.duration_id).checked;
custom.list.resolution = document.getElementById(setup_box.list.resolution_id).checked;
custom.list.views = document.getElementById(setup_box.list.views_id).checked;
custom.list.added_date = document.getElementById(setup_box.list.added_date_id).checked;
custom.list.video_size = document.getElementById(setup_box.list.added_date_id).checked;
custom.list.watch_button = document.getElementById(setup_box.list.watch_button_id).checked;
SetSetupDataListPage();
}
function Make_Html_For_Video_Panel() {
var html = ''+
'<ul style="'+setup_box.video.ul_style+'"><b>About watching preview video</b><br />' +
'<li style="'+setup_box.video.autoplay_style+'"><input type="checkbox" id="'+setup_box.video.autoplay_id+'">Autoplay</li>' +
'<li style="'+setup_box.video.auto_resize_style+'"><input type="checkbox" id="'+setup_box.video.auto_resize_id+'">Auto Resize</li>' +
'<li style="'+setup_box.video.lock_ratio_style+'"><input type="checkbox" id="'+setup_box.video.lock_ratio_id+'">Lock aspect ratio</li>'+
'<li style="'+setup_box.video.width_style+'">Player width <input type="text" id="'+setup_box.video.width_id+'" size="4" value="'+custom.player.player_width+'"> px' +
'</li>'+
'<li style="'+setup_box.video.height_style+'">Player height<input type="text" id="'+setup_box.video.height_id+'" size="4" value="'+custom.player.player_height+'"> px ' +
'<input type="checkbox" id="'+setup_box.video.fit_aspect_ratio_id+'">Fit aspect ratio'+
'</li>'+
'<li style="'+setup_box.video.min_width_style+'">Useful range (width) <input type="text" id="'+setup_box.video.min_width_id+'" size="4" value="'+custom.player.min_width+'"> - '+
'<input type="text" id="'+setup_box.video.max_width_id+'" size="4" value="'+custom.player.max_width+'"> px</li>'+
'<li style="'+setup_box.video.min_height_style+'">Useful range (height) <input type="text" id="'+setup_box.video.min_height_id+'" size="4" value="'+custom.player.min_height+'"> - '+
'<input type="text" id="'+setup_box.video.max_height_id+'" size="4" value="'+custom.player.max_height+'"> px</li>'+
'</ul>'+
'';
return html;
}
function Setup_Video_Panel() {
node = document.getElementById(setup_box.video.autoplay_id);
node.setAttribute('style',setup_box.checkbox.style);
node.checked = custom.player.autoplay;
node = document.getElementById(setup_box.video.auto_resize_id);
node.setAttribute('style',setup_box.checkbox.style);
node.checked = custom.player.auto_resize;
node = document.getElementById(setup_box.video.lock_ratio_id);
node.setAttribute('style',setup_box.checkbox.style);
node.checked = custom.player.lock_ratio;
node = document.getElementById(setup_box.video.width_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = custom.player.player_width;
node = document.getElementById(setup_box.video.height_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = custom.player.player_height;
node = document.getElementById(setup_box.video.fit_aspect_ratio_id);
node.setAttribute('style',setup_box.checkbox.style+setup_box.video.fit_aspect_ratio_style);
node.checked = custom.player.fit_aspect_ratio;
node = document.getElementById(setup_box.video.min_width_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = custom.player.min_width;
node = document.getElementById(setup_box.video.min_height_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = custom.player.min_height;
node = document.getElementById(setup_box.video.max_width_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = custom.player.max_width;
node = document.getElementById(setup_box.video.max_height_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = custom.player.max_height;
}
function Check_Options_Video_Panel() {
var player_width = parseInt(document.getElementById(setup_box.video.width_id).value);
var player_height = parseInt(document.getElementById(setup_box.video.height_id).value);
var min_width = parseInt(document.getElementById(setup_box.video.min_width_id).value);
var min_height = parseInt(document.getElementById(setup_box.video.min_height_id).value);
var max_width = parseInt(document.getElementById(setup_box.video.max_width_id).value);
var max_height = parseInt(document.getElementById(setup_box.video.max_height_id).value);
if(player_width < MIN_WIDTH) return false;
if(player_height < MIN_HEIGHT) return false;
if(player_width > MAX_WIDTH) return false;
if(player_height > MAX_HEIGHT) return false;
if(max_width < MIN_WIDTH) return false;
if(max_height < MIN_HEIGHT) return false;
if(max_width > MAX_WIDTH) return false;
if(max_height > MAX_HEIGHT) return false;
if(min_width < MIN_WIDTH) return false;
if(min_height < MIN_HEIGHT) return false;
if(min_width > MAX_WIDTH) return false;
if(min_height > MAX_HEIGHT) return false;
if(min_width > max_width) return false;
if(min_height > max_height) return false;
if(player_width < min_width) return false;
if(player_height < min_height) return false;
if(player_width > max_width) return false;
if(player_height > max_height) return false;
return true;
}
function Save_Options_Video_Panel() {
custom.player.autoplay = document.getElementById(setup_box.video.autoplay_id).checked;
custom.player.auto_resize = document.getElementById(setup_box.video.auto_resize_id).checked;
custom.player.lock_ratio = document.getElementById(setup_box.video.lock_ratio_id).checked;
custom.player.player_width = parseInt(document.getElementById(setup_box.video.width_id).value);
custom.player.player_height = parseInt(document.getElementById(setup_box.video.height_id).value);
custom.player.fit_aspect_ratio = document.getElementById(setup_box.video.fit_aspect_ratio_id).checked;
custom.player.min_width = parseInt(document.getElementById(setup_box.video.min_width_id).value);
custom.player.min_height = parseInt(document.getElementById(setup_box.video.min_height_id).value);
custom.player.max_width = parseInt(document.getElementById(setup_box.video.max_width_id).value);
custom.player.max_height = parseInt(document.getElementById(setup_box.video.max_height_id).value);
SetSetupDataVideoPanel();
}
function Make_Html_For_Watch_Page() {
var html = ''+
'<ul style="'+setup_box.watch.ul_style+'"><b>About DOWNLOAD button</b><br />' +
'<li style="'+setup_box.watch.disp_type_style+'"><input type="radio" name="'+setup_box.watch.disp_type_name+'" id="'+setup_box.watch.text_type_id+'" value="0">Text type' +
'</li>'+
'<ul style="'+setup_box.watch.ul_style+'">' +
'<li style="'+setup_box.watch.text_color_style+'">Text color <input type="text" id="'+setup_box.watch.text_color_id+'" value="'+custom.watch.text_color+'">' +
'</li>'+
'<li style="'+setup_box.watch.bg_color_style+'">Backgroud color <input type="text" id="'+setup_box.watch.bg_color_id+'" value="'+custom.watch.bg_color+'">' +
'</li>'+
'</ul>'+
'<li style="'+setup_box.watch.disp_type_style+'">'+
'<input type="radio" name="'+setup_box.watch.disp_type_name+'" id="'+setup_box.watch.image_type_id+'" value="1">Image type' +
'</li>'+
'<ul style="'+setup_box.watch.ul_style+'">' +
'<li style="'+setup_box.watch.image_url_style+'">URL <input type="text" id="'+setup_box.watch.image_url_id+'" size="50" value="'+custom.watch.image_url+'">' +
'<br />'+
'</li>'+
'</ul>'+
'</ul>'+
'<br />'+
'<ul style="'+setup_box.watch.ul_style+'"><b>About adding video informations</b><br />' +
'<li style="'+setup_box.watch.video_size_style+'">'+
'<input type="checkbox" id="'+setup_box.watch.video_size_id+'">Video file size</li>' +
'<li style="'+setup_box.watch.added_date_style+'">'+
'<input type="checkbox" id="'+setup_box.watch.added_date_id+'">Added date</li>' +
'</ul>'+
'<br />'+
'<ul style="'+setup_box.watch.ul_style+'"><b>About player</b><br />' +
'<li style="'+setup_box.watch.autoplay_style+'">'+
'<input type="checkbox" id="'+setup_box.watch.autoplay_id+'">Autoplay</li>' +
'</ul>'+
'';
return html;
}
function Setup_Watch_Page() {
var node;
if(custom.watch.disp_type == TEXT_TYPE) {
node = document.getElementById(setup_box.watch.text_type_id);
node.setAttribute('style',setup_box.watch.text_type_style);
node.checked = true;
node = document.getElementById(setup_box.watch.image_type_id);
node.setAttribute('style',setup_box.watch.image_type_style);
} else {
node = document.getElementById(setup_box.watch.image_type_id);
node.setAttribute('style',setup_box.watch.image_type_style);
node.checked = true;
node = document.getElementById(setup_box.watch.text_type_id);
node.setAttribute('style',setup_box.watch.text_type_style);
}
node = document.getElementById(setup_box.watch.text_color_id);
node.setAttribute('style',setup_box.textbox.style);
node = document.getElementById(setup_box.watch.bg_color_id);
node.setAttribute('style',setup_box.textbox.style);
node = document.getElementById(setup_box.watch.image_url_id);
node.setAttribute('style',setup_box.textbox.style);
node = document.getElementById(setup_box.watch.video_size_id);
node.checked = custom.watch.video_size;
node.setAttribute('style',setup_box.checkbox.style);
node = document.getElementById(setup_box.watch.added_date_id);
node.checked = custom.watch.added_date;
node.setAttribute('style',setup_box.checkbox.style);
node = document.getElementById(setup_box.watch.autoplay_id);
node.checked = custom.watch.autoplay;
node.setAttribute('style',setup_box.checkbox.style);
}
function Check_Options_Watch_Page() {
var image_url = document.getElementById(setup_box.watch.image_url_id).value;
var node = document.getElementById(setup_box.watch.image_type_id);
if(node.checked && !image_url) {
return false;
}
return true;
}
function Save_Options_Watch_Page() {
var node = document.getElementById(setup_box.watch.image_type_id);
if(node.checked) {
custom.watch.disp_type = IMAGE_TYPE;
} else {
custom.watch.disp_type = TEXT_TYPE;
}
custom.watch.text_color = document.getElementById(setup_box.watch.text_color_id).value;
custom.watch.bg_color = document.getElementById(setup_box.watch.bg_color_id).value;
custom.watch.image_url = document.getElementById(setup_box.watch.image_url_id).value;
custom.watch.video_size = document.getElementById(setup_box.watch.video_size_id).checked;
custom.watch.added_date = document.getElementById(setup_box.watch.added_date_id).checked;
custom.watch.autoplay = document.getElementById(setup_box.watch.autoplay_id).checked;
SetSetupDataWatchPage();
}
// for script control tab
function Make_Html_For_Script_Control() {
var html = ''+
'<ul style="'+setup_box.script.ul_style+'"><b>About queue control</b><br />' +
'<li style="'+setup_box.script.check_interval_style+'">Check interval<input type="text" id="'+setup_box.script.check_interval_id+'" size="2">sec' +
' (' + MIN_INTERVAL + '-' + MAX_INTERVAL +')</li>' +
'<li style="'+setup_box.script.check_interval_done_style+'">Check interval after finished the process of all videos<input type="text" id="'+setup_box.script.check_interval_done_id+'" size="2">sec' +
' (' + MIN_INTERVAL + '-' + MAX_INTERVAL +')</li>' +
'<li style="'+setup_box.script.max_send_request_style+'">Upper limit of sending HTTP request<input type="text" id="'+setup_box.script.max_send_request_id+'" size="2">' +
' (' + MIN_MAX_SEND + '-' + MAX_MAX_SEND +')</li>' +
'<li style="'+setup_box.script.max_wait_limit_style+'">Upper limit of waiting HTTP response<input type="text" id="'+setup_box.script.max_wait_limit_id+'" size="3">sec' +
' (' + MIN_MAX_WAIT + '-' + MAX_MAX_WAIT +')</li>' +
'<li style="'+setup_box.script.max_retry_style+'">Upper limit of retrying<input type="text" id="'+setup_box.script.max_retry_id+'" size="2">times' +
' (' + MIN_MAX_RETRY + '-' + MAX_MAX_RETRY +')</li>' +
'</ul>'+
'';
return html;
}
function Setup_Script_Control() {
var node;
node = document.getElementById(setup_box.script.check_interval_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = parseInt(custom.queue.check_interval / 1000);
node = document.getElementById(setup_box.script.check_interval_done_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = parseInt(custom.queue.check_interval_done / 1000);
node = document.getElementById(setup_box.script.max_send_request_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = custom.queue.max_send_request;
node = document.getElementById(setup_box.script.max_wait_limit_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = parseInt(custom.queue.max_wait_limit / 1000);
node = document.getElementById(setup_box.script.max_retry_id);
node.setAttribute('style',setup_box.textbox.style);
node.value = parseInt(custom.queue.max_retry);
}
function Check_Options_Script_Control() {
if(/\d+/.test(document.getElementById(setup_box.script.check_interval_id).value) == false) return false;
if(/\d+/.test(document.getElementById(setup_box.script.check_interval_done_id).value) == false) return false;
if(/\d+/.test(document.getElementById(setup_box.script.max_send_request_id).value) == false) return false;
if(/\d+/.test(document.getElementById(setup_box.script.max_wait_limit_id).value) == false) return false;
if(/\d+/.test(document.getElementById(setup_box.script.max_retry_id).value) == false) return false;
var interval = parseInt(document.getElementById(setup_box.script.check_interval_id).value);
var interval_done = parseInt(document.getElementById(setup_box.script.check_interval_done_id).value);
var max_send = parseInt(document.getElementById(setup_box.script.max_send_request_id).value);
var max_wait = parseInt(document.getElementById(setup_box.script.max_wait_limit_id).value);
var max_retry = parseInt(document.getElementById(setup_box.script.max_retry_id).value);
if(interval < MIN_INTERVAL) return false;
if(interval_done < MIN_INTERVAL) return false;
if(max_send < MIN_MAX_SEND) return false;
if(max_wait < MIN_MAX_WAIT) return false;
if(max_retry < MIN_MAX_RETRY) return false;
if(interval > MAX_INTERVAL) return false;
if(interval_done > MAX_INTERVAL) return false;
if(max_send > MAX_MAX_SEND) return false;
if(max_wait > MAX_MAX_WAIT) return false;
if(max_retry > MAX_MAX_RETRY) return false;
return true;
}
function Save_Options_Script_Control() {
custom.queue.check_interval = document.getElementById(setup_box.script.check_interval_id).value * 1000;
custom.queue.check_interval_done = document.getElementById(setup_box.script.check_interval_done_id).value * 1000;
custom.queue.max_send_request = document.getElementById(setup_box.script.max_send_request_id).value;
custom.queue.max_wait_limit = document.getElementById(setup_box.script.max_wait_limit_id).value * 1000;
custom.queue.max_retry = document.getElementById(setup_box.script.max_retry_id).value;
SetSetupDataScriptControl();
}
function Save_Options_Others() {
SetSetupDataOthers();
}
function Player_Visible(mode) {
var node = document.getElementById(video_panel.box.id);
if(node) {
if(mode == true) {
node.style.visibility = '';
} else {
node.style.visibility = 'hidden';
}
}
}
function Close_Box() {
var base = document.getElementById(setup_box.base.id);
setDragObject(null);
document.body.removeChild(base);
Player_Visible(true);
}
function GetEmbedCode(id)
{
var pid = document.getElementById(id).getAttribute('pid');
var url = buildURL(pid, WATCH_URL);
setTimeout(function(){
GM_xmlhttpRequest({
method:"GET",
url: encodeURI(url),
headers:{
"User-Agent":"Mozilla/4.0 (compatible; MSIE 6.0; Win32)",
"Accept":"*/*"
},
onload: function(xhr){
var text = xhr.responseText;
if ( xhr.status != 200 ) { // failed
GM_log(xhr.status + ': ' + text);
return;
}
var VideoInfo = ParseSourceXml(text);
queue[pid]['embedCode'] = VideoInfo['embedCode'];
if(!queue[pid]['embedCode']) {
alert("Can't get embed code\nError message:"+VideoInfo['VideoMovie']);
GM_log("Can't get embed code\nError message:"+VideoInfo['VideoMovie']);
return;
}
// queue[pid]['title'] = VideoInfo['title'];
CloseVideoPanel();
WatchVideo(id);
}
});
},0);
}
// Get Header information
function GetHeaderInformation()
{
if(custom.watch.video_size == false && custom.watch.added_date == false) return;
if(!download_url) {
return;
}
if(download_url_prev == download_url &&
(document.getElementById(added_box_watch.meta.size_id) || document.getElementById(added_box_watch.meta.added_id))) {
return;
}
download_url_prev = download_url;
// var referer = window.location.href; // I cannot send referer.
pidmap[download_url] = '';
RequestHeaderInformation(download_url);
GetHeaderInformationPreviewImage();
}
// Get Header information of the preview image
function GetHeaderInformationPreviewImage()
{
// if(custom.watch.video_size == false && custom.watch.added_date == false) return;
if(!preview_image_url) {
return;
}
if(preview_image_url_prev == preview_image_url &&
document.getElementById(added_box_watch.meta.added_id)) {
return;
}
preview_image_url_prev = preview_image_url;
pidmap[preview_image_url] = '';
RequestHeaderInformation(preview_image_url);
}
function RequestHeaderInformation(url)
{
if(!url) return;
// var ext = /\.jpg$/.test(url);
var method;
var headers = {};
// if(ext) {
method = "HEAD";
headers = {
"User-Agent":"Mozilla/4.0 (compatible; MSIE 6.0; Win32)",
"Accept":"*/*"
};
// } else {
// method ="GET";
// headers = {
// "User-Agent":"Mozilla/4.0 (compatible; MSIE 6.0; Win32)",
// "Range":"bytes=0-1",
// "Accept":"*/*"
// };
// }
setTimeout(function(){
GM_xmlhttpRequest({
method: method,
url: encodeURI(url),
headers: headers,
onload: function(xhr){
var headers = xhr.responseHeaders;
if ( xhr.status != 200 &&
xhr.status != 206) { // failed
GM_log(xhr.status + ': ' + headers);
return;
}
var mode;
var ext = /\.jpg$/.test(xhr.finalUrl);
if(ext) {
mode = 1;
pid = pidmap[xhr.finalUrl];
} else {
mode = 0;
var permalinkid = xhr.finalUrl.match(/\/([^\/]+)$/)[1];
pid = pidmap[permalinkid];
}
ParseResponseHeaders(headers, mode, pid);
if(watch_page == true) {
AddMetaData_Watch(mode);
} else {
WaitMessage(pid, 0);
AddMetaData(pid);
}
}
});
},0);
}
// Get Header information for list page
function GetHeaderInformationList(pid)
{
if(custom.list.video_size == false && custom.list.added_date == false) return;
// var referer = window.location.href; // I cannot send referer.
if(queue[pid]['video_url']) {
var permalinkid = queue[pid]['video_url'].match(/\/\d+?\/(.*?)\?/)[1];
pidmap[permalinkid] = pid;
}
pidmap[queue[pid]['previewimage_url']] = pid;
if(custom.list.added_date) {
RequestHeaderInformation(queue[pid]['previewimage_url']);
}
if(custom.list.video_size) {
RequestHeaderInformation(queue[pid]['video_url']);
}
}
function ParseResponseHeaders(headers, target, pid) {
if(target == 0) { // video only
if(!document.getElementById(added_box_watch.meta.size_id)) {
var size = GetContentLength(headers);
if(pid) {
queue[pid]['size'] = size;
} else {
header_info.size = size;
}
}
}
if(!document.getElementById(added_box_watch.meta.added_id)) {
var added = GetAddedDate(headers);
if(pid) {
queue[pid]['addedDate'] = added.replace(' GMT','');
} else {
header_info.added = added;
}
}
}
function AddMetaData_Watch(target) {
var xp = document.evaluate('//div[@id="right-small"]/div[1]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var l=xp.snapshotLength;
if(l == 0) {
return;
}
var div = xp.snapshotItem(0);
if(target == 0) { // video only
if(!document.getElementById(added_box_watch.meta.size_id)) {
AddContentLength(div, header_info.size);
}
}
if(!document.getElementById(added_box_watch.meta.added_id)) {
AddAddedDate(div, header_info.added);
}
}
function GetContentLength(headers) {
var size = '';
p = headers.match(/Content-Length: (\d+)/);
if(p) {
var cont_len = RegExp.$1;
var cont_len_kb = parseInt(cont_len / 1024);
var cont_len_mb = Math.round(cont_len / (1024*1024));
if(cont_len_mb >= 10) {
size = size + cont_len_mb + ' MB';
} else {
size = size + cont_len_kb + ' KB';
}
size = size + '(' + cont_len + ' B)';
}
return size;
}
function GetAddedDate(headers) {
var added = '';
var p = headers.match(/Last-Modified: (.*)/);
if(p) {
var datestr = RegExp.$1;
var disp_str = datestr.substr(5);
// var monthstr = ["Jan","Feb","Mar","Apl","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
// var da = datestr.split(/[ ,]/);
// p = ("0"+(monthstr.indexOf(da[3])+1)).substr(-2);
// da[3] = da[2];
// da[2] = p;
// var disp_str = da.slice(2,5).join('/')+" "+da.slice(5,7).join(' ');
added = disp_str;
}
return added;
}
function AddContentLength(div, size) {
if(size) {
p = document.createElement('p');
p.id = added_box_watch.meta.size_id;
p.innerHTML = '<strong>Size:</strong> '+size;
div.parentNode.insertBefore(p, div);
if(custom.watch.video_size == false) {
p.setAttribute('style', styles.close);
}
}
}
function AddAddedDate(div, disp_str) {
if(disp_str) {
var p = document.createElement('p');
p.id = added_box_watch.meta.added_id;
p.innerHTML = '<strong>Added:</strong> '+disp_str;
div.parentNode.insertBefore(p, div);
if(custom.watch.added_date == false) {
p.setAttribute('style', styles.close);
}
}
}
////// for update checker
var force_check = false;
function IsNecessaryUpdateCheck() {
var now = new Date();
var now_yy = now.getYear();
var now_mm = now.getMonth();
var now_dd = now.getDate();
var now_day = now.getDay();
var dist = now.getTime()/(1000 * 60 * 60 * 24) - update_check.last_check_date/(1000 * 60 * 60 * 24);
dist = Math.floor(dist);
var prev = new Date();
prev.setTime(update_check.last_check_date);
var yy = prev.getYear();
var mm = prev.getMonth();
var dd = prev.getDate();
var day = prev.getDay();
switch(update_check.type) {
case ONCE_A_DAY:
if(yy != now_yy ||
mm != now_mm ||
dd != now_dd) return true;
break;
case ONCE_A_WEEK:
if(update_check.specified_day == ANY_DAY) {
if(day > now_day) {
return true;
} else if(day == now_day) {
if(yy != now_yy ||
mm != now_mm ||
dd != now_dd) return true;
} else {
if(now_day < dist) return true;
}
} else
if(update_check.specified_day == now_day) {
if(yy != now_yy ||
mm != now_mm ||
dd != now_dd) return true;
}
break;
case ONCE_A_MONTH:
if(yy != now_yy) return true;
if(mm != now_mm) return true;
break;
}
return false;
}
function ParseScriptPage(text)
{
var data = {version:'', title:"Unknown" };
var div = document.createElement('div');
div.innerHTML = text;
var node = document.evaluate('.//h1[@class="title"]', div, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if(node) {
data.title = node.textContent;
}
var node = document.evaluate('.//td[@id="summary"]', div, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if(node) {
var ver = node.textContent.match(/Version:[\n|\s]*(.*?)\n/)[1];
if(ver) {
data.version = ver;
}
}
return data;
}
function CheckScriptVersion(version) {
var work = THIS_VER.split('.');
var major_ver = parseInt(work[0]);
var minor_ver = parseInt(work[1]);
var sub_ver = 0;
if(work[2]) sub_ver = parseInt(work[2]);
work = version.split('.');
var major_ver_uso = parseInt(work[0]);
var minor_ver_uso = parseInt(work[1]);
var sub_ver_uso = 0;
if(work[2]) sub_ver_uso = parseInt(work[2]);
if(major_ver < major_ver_uso) {
return true;
}
if(major_ver == major_ver_uso &&
minor_ver < minor_ver_uso) {
return true;
}
if(major_ver == major_ver_uso &&
minor_ver == minor_ver_uso &&
sub_ver < sub_ver_uso) {
return true;
}
return false;
}
function DispMessage(title, html, base_style) {
var base = document.createElement('div');
base.id = MSGBOX_ID;
base.setAttribute('style', 'position:fixed;top:0px;left:0px;height:60px;padding-right:140px;z-index:200000;'+base_style);
var node = document.createElement('div');
node.innerHTML = title + " (V"+THIS_VER+")";
node.setAttribute('style', 'color:#000000;font-size:20px;margin-left:10px;height:30px;');
base.appendChild(node);
node = document.createElement('div');
node.innerHTML = html;
node.setAttribute('style', 'color:#000000;font-size:20px;margin-left:10px;height:30px;');
base.appendChild(node);
var setup = document.createElement('input');
setup.type = "button";
setup.value = "Set up";
setup.addEventListener('click', Setup, false);
setup.setAttribute('style', 'position:absolute; right:60px; bottom:5px; height:24px;width:60px;margin-left:20px;border:3px outset buttonface;background-color:buttonface;color:#000000;font-weight:bold;cursor:pointer;');
base.appendChild(setup);
var close = document.createElement('input');
close.type = "button";
close.value = "X";
close.addEventListener('click', function(e) {
var id = MSGBOX_ID;
var node = document.getElementById(id);
if(node) {
node.parentNode.removeChild(node);
}
update_check.last
}, false);
close.setAttribute('style', 'position:absolute; right:5px; top:5px; height:28px;width:28px;margin-left:20px;border:3px outset buttonface;background-color:buttonface;color:#000000;font-weight:bold;font-size:12px;cursor:pointer;');
base.appendChild(close);
document.body.appendChild(base);
}
function DispUpdateCheckError(data) {
var html = "Can't get script information from USO";
DispMessage(data.title, html, "background-color:#FF00FF;");
}
function DispUpdateMessage(data) {
var html = 'V'+data.version+' has been released. Visit <a href="'+THIS_URL+'" style="text-decoration:underline;color:#0044FF;">the script page</a>.</span>';
DispMessage(data.title, html, "background-color:#FFFF00;");
}
function DispNoUpdateMessage(data) {
var html = 'A new version has not been released.';
DispMessage(data.title, html, "background-color:#00FFFF;");
}
function ExecuteUpdateCheck() {
setTimeout(function(){
GM_xmlhttpRequest({
method:"GET",
url: THIS_URL,
headers:{
"User-Agent": "Mozilla/4.0 (compatible; MSIE 6.0; Win32)",
"Accept":"*/*",
"Accept-Language":"en-us"
},
onload: function(xhr){
var text = xhr.responseText;
if ( xhr.status != 200 ) { // failed
var data = {title: "HTTP Error "+xhr.status, version:""};
DispUpdateCheckError(data);
GM_log(xhr.status + ': ' + text);
return;
}
update_check.last_check_date = (new Date()).getTime();
SetSetupDataUpdateCheck();
var data = ParseScriptPage(text);
if(data.version) {
if(CheckScriptVersion(data.version)) {
DispUpdateMessage(data);
} else if(force_check == true){
DispNoUpdateMessage(data);
force_check = false;
}
} else {
DispUpdateCheckError(data);
}
}
});
},0);
}
function UpdateCheck(mode) {
if(mode == true) {
ExecuteUpdateCheck();
} else {
switch(update_check.type) {
case NO_CHECK:
break;
case EVERY_LOADING:
ExecuteUpdateCheck();
break;
case ONCE_A_DAY:
case ONCE_A_WEEK:
case ONCE_A_MONTH:
if(IsNecessaryUpdateCheck()) {
ExecuteUpdateCheck();
}
break;
}
}
}
function Update_Check_Force() {
force_check = true;
UpdateCheck(true);
}
function Make_Html_For_Update_Checker() {
var html = ''+
'<ul style="'+setup_box.update.ul_style+'"><b>About check pattern</b><br />' +
'<li style="'+setup_box.update.li_style+'"><input type="radio" name="'+setup_box.update.type_name+'" id="'+setup_box.update.no_check_id+'">No check</li>' +
'<li style="'+setup_box.update.li_style+'"><input type="radio" name="'+setup_box.update.type_name+'" id="'+setup_box.update.every_loading_id+'">Every loading</li>' +
'<li style="'+setup_box.update.li_style+'"><input type="radio" name="'+setup_box.update.type_name+'" id="'+setup_box.update.once_a_day_id+'">Once a day</li>' +
'<li style="'+setup_box.update.li_style+'"><input type="radio" name="'+setup_box.update.type_name+'" id="'+setup_box.update.once_a_week_id+'">Once a week</li>' +
'<div id="'+setup_box.update.day_box_id+'" style="'+setup_box.update.day_box_style+'">' +
'<ul style="'+setup_box.update.ul_style+'">' +
'<li style="'+setup_box.update.li_style+'">' +
'<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.any_day_id+'">Any day' +
'<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.sunday_id+'">Sunday' +
'<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.monday_id+'">Monday' +
'<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.tuesday_id+'">Tuesday' +
'</li>'+
'<li style="'+setup_box.update.li_style+'">'+
'<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.wednesday_id+'">Wednesday' +
'<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.thursday_id+'">Thursday' +
'<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.friday_id+'">Friday' +
'<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.saturday_id+'">Saturday' +
'</li>'+
'</ul>'+
'</div>'+
'<li style="'+setup_box.update.li_style+'"><input type="radio" name="'+setup_box.update.type_name+'" id="'+setup_box.update.once_a_month_id+'">Once a month</li>' +
'</ul>'+
'';
return html;
}
function Setup_Update_Check() {
var node;
node = document.getElementById(setup_box.update.no_check_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.type == NO_CHECK) {
node.checked = true;
}
node = document.getElementById(setup_box.update.every_loading_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.type == EVERY_LOADING) {
node.checked = true;
}
node = document.getElementById(setup_box.update.once_a_day_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.type == ONCE_A_DAY) {
node.checked = true;
}
node = document.getElementById(setup_box.update.once_a_week_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.type == ONCE_A_WEEK) {
node.checked = true;
}
node = document.getElementById(setup_box.update.once_a_month_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.type == ONCE_A_MONTH) {
node.checked = true;
}
node = document.getElementById(setup_box.update.any_day_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.specified_day == ANY_DAY) {
node.checked = true;
}
node = document.getElementById(setup_box.update.sunday_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.specified_day == SUNDAY) {
node.checked = true;
}
node = document.getElementById(setup_box.update.monday_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.specified_day == MONDAY) {
node.checked = true;
}
node = document.getElementById(setup_box.update.tuesday_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.specified_day == TUESDAY) {
node.checked = true;
}
node = document.getElementById(setup_box.update.wednesday_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.specified_day == WEDNESDAY) {
node.checked = true;
}
node = document.getElementById(setup_box.update.thursday_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.specified_day == THURSDAY) {
node.checked = true;
}
node = document.getElementById(setup_box.update.friday_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.specified_day == FRIDAY) {
node.checked = true;
}
node = document.getElementById(setup_box.update.saturday_id);
node.setAttribute('style',setup_box.radio.style);
if(update_check.specified_day == SATURDAY) {
node.checked = true;
}
}
function Check_Options_Update_Checker() {
return true;
}
function Save_Options_Update_Checker() {
var type;
if(document.getElementById(setup_box.update.no_check_id).checked == true) {
type = NO_CHECK;
} else
if(document.getElementById(setup_box.update.every_loading_id).checked == true) {
type = EVERY_LOADING;
} else
if(document.getElementById(setup_box.update.once_a_day_id).checked == true) {
type = ONCE_A_DAY;
} else
if(document.getElementById(setup_box.update.once_a_week_id).checked == true) {
type = ONCE_A_WEEK;
} else
if(document.getElementById(setup_box.update.once_a_month_id).checked == true) {
type = ONCE_A_MONTH;
}
update_check.type = type;
var day;
if(document.getElementById(setup_box.update.any_day_id).checked == true) {
day = ANY_DAY;
} else
if(document.getElementById(setup_box.update.sunday_id).checked == true) {
day = SUNDAY;
} else
if(document.getElementById(setup_box.update.monday_id).checked == true) {
day = MONDAY;
} else
if(document.getElementById(setup_box.update.tuesday_id).checked == true) {
day = TUESDAY;
} else
if(document.getElementById(setup_box.update.wednesday_id).checked == true) {
day = WEDNESDAY;
} else
if(document.getElementById(setup_box.update.thursday_id).checked == true) {
day = THURSDAY;
} else
if(document.getElementById(setup_box.update.friday_id).checked == true) {
day = FRIDAY;
} else
if(document.getElementById(setup_box.update.saturday_id).checked == true) {
day = SATURDAY;
} else {
return; // bug
}
update_check.specified_day = day;
SetSetupDataUpdateCheck();
}
})();
