How to use getSourceXml method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

41901.user.js

Source:41901.user.js Github

copy

Full Screen

1// ==UserScript==2// @name Adds a link to download original file for Veoh3// @namespace http://userscripts.org/users/760784// @version 2.11.35// @author charmy6// @description Adds a link to download original videos and preview videos.7// @include http://www.veoh.com/*8// @exclude http://www.veoh.com/ad/*9// ==/UserScript==1011(function() {1213// for update check14const THIS_SCRIPT_NO = '41901';15const THIS_URL = 'http://userscripts.org/scripts/show/'+THIS_SCRIPT_NO;16const THIS_VER = '2.11.3';17const MSGBOX_ID = "USO_USER_SCRIPT_UPDATE_CHECK_"+THIS_SCRIPT_NO1819const NO_CHECK = 0;20const EVERY_LOADING = 1;21const ONCE_A_DAY = 2;22const ONCE_A_WEEK = 3;23const ONCE_A_MONTH = 4;2425// option of 'Once a week' mode26const ANY_DAY = -1; // on the first loading of a week27const SUNDAY = 0;28const MONDAY = 1;29const TUESDAY = 2;30const WEDNESDAY = 3;31const THURSDAY = 4;32const FRIDAY = 5;33const SATURDAY = 6;343536var update_check = {37 type: ONCE_A_WEEK,38 last_check_date: 0,39 specified_day: ANY_DAY,40};414243const TEXT_TYPE = 0;44const IMAGE_TYPE = 1;4546// for player size47const MIN_WIDTH = 128; // 640/548const MIN_HEIGHT = 96; // 480/549const MAX_WIDTH = 2560; // 640*450const MAX_HEIGHT = 1920; // 480*451const DEFAULT_PLAYER_WIDTH = 480; //original value is 41052const DEFAULT_PLAYER_HEIGHT = 385; // original value is 3415354// for script control55const NONE = 0;56const SENT_REQUEST = 1;57const RECEIVED_RESPONSE = 2;58const STORED_DATA = 3;59const NOT_RECEIVED = 4;60const CLONE_DATA = 9;61var queue = new Array(0);6263const MAX_SEND_REQUEST = 20; // up to 20 http request at the same time64const QUEUE_CHECK_INTERVAL = 5*1000; // 5 sec.65const QUEUE_CHECK_INTERVAL_DONE = 10*1000; // 10 sec.66const MAX_WAIT_LIMIT = 120*1000; // 120 sec67const MAX_RETRY = 3; // 3 times6869const MIN_INTERVAL = 3;70const MIN_MAX_SEND = 1;71const MIN_MAX_WAIT = 30;72const MIN_MAX_RETRY = 0;73const MAX_INTERVAL = 60;74const MAX_MAX_SEND = 25;75const MAX_MAX_WAIT = 300;76const MAX_MAX_RETRY = 10;7778var current_request_num = 0;79var total_queue_num = 0;80var retry_count = 0;81var check_interval = 0;8283// for watch page84var permalink = '';85var openVideoInformation = false;8687// for list page88var need_information = false;8990// for auto pager91// If you want to load thumbnails automatically at the page inserted by auto pager add-on, set true.92// If you want to stop this function,set false.93var load_thumbnails = true;9495// You can customize initial value.96const SETUP_VERSION = 4;97var custom = {98 setup_version: 0,99 player: {100 autoplay: false, // true or false101 auto_resize: false, // true or false102 player_height: DEFAULT_PLAYER_HEIGHT, // pixel value103 player_width: DEFAULT_PLAYER_WIDTH, // pixel value104 min_height: MIN_HEIGHT, // pixel value, minimum height of resizing105 min_width: MIN_WIDTH, // pixel value, minimum width of resizing106 max_height: 768, // pixel value, maximum height of resizing107 max_width: 1024, // pixel value, maximum width of resizing108 lock_ratio: true, // true only109 fit_aspect_ratio: false, // true or false110 top: 'center', // pixel value or 'center'111 left: 'center', // pixel value or 'center'112 download_preview: true,113 download_preview_text: 'Download preview video',114 },115 list: {116 check_box_option: false,117 username: false,118 filesize: false,119 filesize_byte: true,120 dateAdded: false,121 downloads: false,122 views: false,123 numofcomments: false,124 rating: false,125 preview_button: false,126 download_preview: false,127 download_link_text: 'Download',128 preview_button_text: 'Preview',129 download_preview_text: 'Download preview',130 },131 watch: {132 autoplay: true, // not supported133 download_original: true,134 download_preview: true,135 iPhone: true,136 detail_information: false,137 meta_data_option: false,138 convert_utf8: false,139 download_link_text: 'Download original video',140 preview_button_text: 'Preview',141 download_preview_text: 'Download preview video',142 iPhone_text: 'Go to iPhone page',143 },144 queue: {145 check_interval: QUEUE_CHECK_INTERVAL,146 check_interval_done: QUEUE_CHECK_INTERVAL_DONE,147 max_send_request: MAX_SEND_REQUEST,148 max_wait_limit: MAX_WAIT_LIMIT,149 max_retry: MAX_RETRY,150 },151 style: {152 list: {153 base: {154 text_color: "",155 bg_color: "rgba(255,255,255,0.7)",156 bg_image: "",157 font_size: "0.9em",158 font_weight: "",159 others: "",160 },161 download_buttons: {162 text_color: "#FFFFFF",163 bg_color: "#3FC651",164 bg_image: "",165 font_size: "",166 font_weight: "bold",167 others: "",168 },169 download_link: {170 text_color: '#0054A6',171 bg_color: '',172 bg_image: 'none',173 font_size: "",174 font_weight: "",175 others: "",176 },177 name: {178 text_color: '#0000FF',179 bg_color: '',180 bg_image: 'none',181 font_size: "",182 font_weight: "",183 others: "",184 },185 meta: {186 text_color: "#008800",187 bg_color: "",188 bg_image: "",189 font_size: "1em",190 font_weight: "",191 others: "",192 },193 preview_button: {194 text_color: "#FFFFFF",195 bg_color: "#3FC651",196 bg_image: "",197 font_size: "",198 font_weight: "bold",199 others: "",200 },201 preview_download: {202 text_color: '#0054A6',203 bg_color: '',204 bg_image: 'none',205 font_size: "",206 font_weight: "",207 others: "",208 },209 wait: {210 text_color: "#FF0000",211 bg_color: "",212 bg_image: "",213 font_size: "1em",214 font_weight: "",215 others: "",216 },217 error: {218 text_color: "#FF0000",219 bg_color: "",220 bg_image: "",221 font_size: "1em",222 font_weight: "bold",223 others: "",224 },225 },226 watch: {227 base: {228 text_color: "",229 bg_color: "transparent",230 bg_image: "",231 font_size: "1.0em",232 font_weight: "",233 others: "",234 },235 download: {236 text_color: '',237 bg_color: 'transparent',238 bg_image: 'none',239 font_size: "",240 font_weight: "",241 others: "",242 },243 anchor: {244 text_color: '#2F73AF',245 bg_color: 'transparent',246 bg_image: '',247 font_size: "",248 font_weight: "bold",249 others: "",250 },251 title: {252 text_color: '',253 bg_color: 'transparent',254 bg_image: '',255 font_size: "",256 font_weight: "bold",257 others: "",258 },259 meta: {260 text_color: "",261 bg_color: "",262 bg_image: "",263 font_size: "",264 font_weight: "",265 others: "",266 },267 },268 video_panel: {269 base: {270 text_color: "",271 bg_color: "rgba(0,0,0,0.9)",272 bg_image: "",273 font_size: "1.0em",274 font_weight: "",275 others: "",276 },277 title: {278 text_color: '#FFFFFF',279 bg_color: 'transparent',280 bg_image: 'none',281 font_size: "14px",282 font_weight: "bold",283 others: "",284 },285 download: {286 text_color: '#FFFFFF',287 bg_color: '#3FC651',288 bg_image: 'none',289 font_size: "",290 font_weight: "bold",291 others: "",292 },293 anchor: {294 text_color: '#FFFFFF',295 bg_color: '#3FC651',296 bg_image: 'none',297 font_size: "",298 font_weight: "bold",299 others: "",300 },301 lock: {302 text_color: '#FFFFFF',303 bg_color: '#3FC651',304 bg_image: 'none',305 font_size: "",306 font_weight: "bold",307 others: "",308 },309 close: {310 text_color: '#FFFFFF',311 bg_color: '#3FC651',312 bg_image: 'none',313 font_size: "",314 font_weight: "bold",315 others: "",316 },317 status_bar: {318 text_color: '#FFFF00',319 bg_color: '#404040',320 bg_image: 'none',321 font_size: "",322 font_weight: "",323 others: "",324 },325 },326 },327};328329var green_button_style = 'margin-right:10px;cursor:pointer;padding:2px;border:0px;-moz-border-radius:1px;';330var link_button_style = 'display:inline;font-size:12px;font-weight:bold;height:22px;width:192px;padding:8px 30px 8px 30px;';331var button_style = 'cursor:pointer;-moz-border-radius:1px;';332var tooltip_style = 'position:fixed;z-index:20000;margin-right:10px;background-color:#FFFFAA;color:#000000;font-weight:bold;padding:2px;border:0px;-moz-border-radius:1px;';333334// for watch pages335var added_box_watch = {336 base: {337 id: 'AddsALinkDownloadBase',338 style: 'margin:6px 0px 10px 0px;',339 },340 //// id and style for 'Get URL' button341 geturl: {342 show: false,343 id: 'AddsALinkGetURLButton',344 style: 'display:inline;position:relative;left:10px;margin-right:20px;margin-bottom:20px;'345 },346347 // for original video download button348 original: {349 download_url: '',350 div_id: 'AddsALinkDownloadBaseForOriginalFile',351 div_style: '',352 span_id: 'AddsALinkDownloadBoxForOriginalFile',353 anchor_id: 'AddsALinkDownloadURLForOriginalFile',354 anchor_style: link_button_style,355 title_id: 'AddsALinkTitleBoxForOriginalFile',356 title_style: 'display:block;margin-top:20px;margin-right:20px;margin-bottom:10px;'357 },358359 // for preview video download button360 preview: {361 download_url: '',362 div_id: 'AddsALinkDownloadBaseForPreviewFile',363 div_style: '',364 span_id: 'AddsALinkDownloadBoxForPreviewFile',365 anchor_id: 'AddsALinkDownloadURLForPreviewFile',366 anchor_style: link_button_style,367 title_id: 'AddsALinkTitleBoxForPreviewFile',368 title_style: 'display:block;margin-top:10px;margin-right:20px;margin-bottom:10px;'369 },370371 // for Go to iPhone button372 mp4: {373 download_url: '',374 div_id: 'AddsALinkDownloadBaseForMp4',375 div_style: '',376 span_id: 'AddsALinkDownloadBoxForMp4',377 anchor_id: 'AddsALinkDownloadURLForMp4',378 anchor_style: link_button_style,379 title_id: 'AddsALinkTitleBoxForMp4',380 title_style: 'display:block;margin-top:10px;margin-right:20px;margin-bottom:10px;'381 },382383 // information box and button in watch pages384 info: {385 btn_id: 'AddsALinkVideoInformationButton',386 btn_style: 'display:inline;position:relative;left:10px;margin-right:20px;margin-bottom:20px;',387 box_id: 'AddsALinkVideoDetailInformation',388 caption_id: 'AddsALinkVideoInfomationCaption',389 parent_id: 'AddsALinkVideoInfomationParentBox'390 },391392 meta: {393 rating_dt_id: 'AddsALinkWatchRatingDT',394 rating_dd_id: 'AddsALinkWatchRatingDD',395 downloads_dt_id: 'AddsALinkWatchDwonloadsDT',396 downloads_dd_id: 'AddsALinkWatchDwonloadsDD',397 rating_dt_style: '',398 rating_dd_style: '',399 downloads_dt_style: '',400 downloads_dd_style: ''401 },402403// for watch button404 watch: {405 id: 'AddsALinkWatchWatchButton',406 style: button_style+'margin-bottom:6px;',407 },408409// for the box instead of the player410 player: {411 id: 'AddsALinkWatchDummyPlayer',412 style: 'background-color:#FFFFFF;',413 },414415}416417// for open/close a box418var styles = {419 block_open: 'display:block;',420 inline_open: 'display:inline;margin-top:10px;',421 close: 'display:none;'422};423424425//// for video list426// added box for the checkbox and the download link427var added_box = {428 chkbox: {429 id: 'AddsALinkCheckBox_',430 style: 'display:inline;margin-right:5px;'431 },432 base: {433 id: 'AddsALinkBase_',434 style: ''435 },436 download: {437 id: 'AddsALinkDownloadLink_',438 style: ''439 },440 meta: {441 id: 'AddsALinkMetaBox_',442 name_id: 'AddsALinkMetaUsername_',443 wait_id: 'AddsALinkMetaWait_',444 style: '',445 name_style: '',446 wait_style: ''447 },448 tooltip: {449 id: 'AddsALinkTooltip',450 style: tooltip_style,451 distanceX: 0,452 distanceY: 12453 },454 preview_download: {455 id: 'AddsALinkPreviewDownload_',456 style: 'cursor:pointer;'457 },458 preview: {459 id: 'AddsALinkPreview_',460 style: green_button_style461 }462};463464var video_panel = {465 box: {466 id: 'AddsALinkVideoPanel',467 style: 'padding:20px 20px 50px 20px;position:fixed;z-index:20000;display:block;cursor:move;',468 close_style: 'display:none;'469 },470 title: {471 id: 'AddsALinkWatchTitle',472 style: 'position:absolute;margin-top:6px;text-align:center;top:0px;left:0px;width:100%;'473 },474 player: {475 id: 'AddsALinkPlayer',476 style: 'margin:20px 0px 0px 0px;'477 },478 preview_download: {479 type: 'link', // 'button' or 'link'480 id: 'AddsALinkPreviewDownloadButton',481 style: green_button_style+'float:right;'482 },483 lock: {484 id: 'AddsALinkLockButton',485 style: button_style+'position:absolute;top:0px;right:25px;'486 },487 close: {488 id: 'AddsALinkCloseButton',489 style: button_style+'position:absolute;top:0px;right:5px;'490 },491// lock_ratio: {492// id: 'AddsALinkLockRatioChkbox',493// style: 'height:14px;position:absolute;bottom:30px;left:10px;',494// label_style: 'height:14px;position:absolute;bottom:30px;left:30px;color:#FFFFFF;'495// },496 status_bar: {497 id: 'AddsALinkStatusBar',498 style: 'height:14px;width:99%;position:absolute;bottom:0px;left:0px;padding:0px 2px 2px 2px;text-align:left;'499 },500 resize: {501 id: 'AddsALinkResizeBox',502 style: 'height:16px;width:16px;position:absolute;bottom:0px;right:0px;background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAIAAACQKrqGAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAB9SURBVHjaYrxy4QQDcQAggJiIUaStbw4kAQKIiRh1jY2NQAZAADERqQ4IAAKIiRh1IQEeQBIggJiIUQdxK0AAMRGjDsIGCCAmItUBAUAAMRGjDuJWgABiIkYdxK0AAcREjDoIGyCAmIhUBwQAAcREjDqIWwECiJH45AIQYACQSUAeiz1vwgAAAABJRU5ErkJggg==");'503 }504};505506// added buttons507var added_buttons = {508 top: { // parent box(top box)509 id: 'AddsALinkButtonsTopBox',510 style: 'margin-top:10px;'511 },512 bottom: { // parent box(bottom box)513 id: 'AddsALinkButtonsBottomBox',514 style: 'margin-top:10px;'515 },516 select: { // Select All517// id: 'AddsALinkSelectAllButton',518 style: green_button_style519 },520 clear: { // Clear All521// id: 'AddsALinkClearAllButton',522 style: green_button_style523 },524 download: { // Download selected videos525// id: 'AddsALinkDownloadButton',526 style: green_button_style527 },528};529530// for setup531const li_style_base = "padding-top:6px;font-size:12px;";532const indent_1 = "padding-left:10px;";533const indent_2 = "padding-left:24px;";534const indent_3 = "padding-left:48px;";535const ul_style = 'padding-left:20px;padding-top:6px;list-style:none inside;';536const li_style = indent_1+li_style_base;537const li_style_text = indent_2+li_style_base;538const tab_base_style = "position:absolute;top:40px;text-align:center;height:40px;width:64px;cursor:pointer;z-index:2;-moz-border-radius:3px;";539const tab_style = tab_base_style+"font-weight:normal;border:3px inset buttonface;";540const tab_style_active = tab_base_style+"font-weight:bold;border:3px outset buttonface;border-bottom:3px solid buttonface;";541const setup_box_style = "z-index:1;display:none;";542const setup_box_style_active = "z-index:1;display:block;";543var setup_box = {544 base: {545 id: 'AddsALinkSetupBox',546 style: 'position:fixed;width:450px;color:#000000;background-color:buttonface;border:3px outset buttonface;font-size:14px;padding-top:6px;z-index:200000;text-align:left;',547 title_style: 'text-align:center;margin:0 0 5px 0;font-weight:bold;',548 tabs_style: 'margin:0 0 20px 0;font-weight:bold;height:40px;',549 hr_style: 'border: 0px solid black;border-bottom:1px solid #000000;',550 box_style: setup_box_style,551 box_style_active: setup_box_style_active,552 ul_style: 'list-style:none inside;',553 },554 tabs: {555 list: {556 id: 'AddsALinkSetupBoxListTab',557 box_id: 'AddsALinkSetupBoxListBox',558 style: tab_style+'left:0px;',559 style_active: tab_style_active+'left:0px;',560 },561 video: {562 id: 'AddsALinkSetupBoxVideoTab',563 box_id: 'AddsALinkSetupBoxVideoBox',564 style: tab_style+'left:70px;',565 style_active: tab_style_active+'left:70px;',566 },567 watch: {568 id: 'AddsALinkSetupBoxWatchTab',569 box_id: 'AddsALinkSetupBoxWatchBox',570 style: tab_style+'left:140px;',571 style_active: tab_style_active+'left:140px;',572 },573 script: {574 id: 'AddsALinkSetupBoxScriptControlTab',575 box_id: 'AddsALinkSetupBoxScriptControlBox',576 style: tab_style+'left:210px;',577 style_active: tab_style_active+'left:210px;',578 },579 update: {580 id: 'AddsALinkSetupBoxUpdateCheckerTab',581 box_id: 'AddsALinkSetupBoxUpdateCheckerBox',582 style: tab_style+'left:280px;',583 style_active: tab_style_active+'left:280px;',584 }585 },586 watch: {587 text_color_id: 'AddsALinkSetupWatchTextColor',588 bg_color_id: 'AddsALinkSetupWatchBGColor',589 bg_image_id: 'AddsALinkSetupWatchBGImage',590 download_original_id: 'AddsALinkSetupWatchDownloadOriginalVideo',591 download_link_text_id: 'AddsALinkSetupWatchDownloadLinkText',592 download_preview_id: 'AddsALinkSetupWatchDownloadPreviewVideo',593 download_preview_text_id: 'AddsALinkSetupWatchDownloadPreviewText',594 iPhone_id: 'AddsALinkSetupWatchGoToIPhone',595 iPhone_text_id: 'AddsALinkSetupWatchGoToIPhoneText',596 information_id: 'AddsALinkSetupWatchVideoInformations',597 meta_data_id: 'AddsALinkSetupWatchMetaData',598 convert_utf8_id: 'AddsALinkSetupWatchConvertUTF8',599 disp_type_style: 'margin:5px 0 0 0;',600 title_style: 'text-align:center;margin:0 0 5px 0;font-weight:bold;',601 ul_style: ul_style,602 ul_style_off: 'display:none;',603 text_color_style: li_style_text,604 bg_color_style: li_style_text,605 bg_image_style: li_style_text,606 download_original_style: li_style,607 download_link_text_style: indent_3+li_style_base,608 download_preview_style: li_style,609 download_preview_text_style: indent_3+li_style_base,610 iPhone_style: li_style,611 iPhone_text_style: indent_3+li_style_base,612 information_style: li_style,613 meta_data_style: li_style,614 convert_utf8_style: li_style,615 },616 list: {617 checkbox_id: 'AddsALinkSetupListCheckBox',618 download_link_text_id: 'AddsALinkSetupListDownloadText',619 preview_button_id: 'AddsALinkSetupListWatchButton',620 preview_button_text_id: 'AddsALinkSetupListWatchButtonText',621 download_preview_id: 'AddsALinkSetupListDownloadPreview',622 download_preview_text_id: 'AddsALinkSetupListDownloadPreviewText',623 publisher_id: 'AddsALinkSetupListPublisher',624 filesize_id: 'AddsALinkSetupListFileSize',625 filesize_byte_id: 'AddsALinkSetupListFileSizeByte',626 added_date_id: 'AddsALinkSetupListAddedDate',627 views_id: 'AddsALinkSetupListViews',628 downloads_id: 'AddsALinkSetupListDownloads',629 comments_id: 'AddsALinkSetupListComments',630 rating_id: 'AddsALinkSetupListRating',631 title_style: 'text-align:center;margin:0 0 5px 0;font-weight:bold;',632 ul_style: ul_style,633 chkeckbox_style: li_style,634 download_link_text_style: indent_3+li_style_base,635 preview_button_style: li_style,636 preview_button_text_style: indent_3+li_style_base,637 download_preview_style: li_style,638 download_preview_text_style: indent_3+li_style_base,639 publisher_style: li_style,640 filesize_style: li_style,641 added_date_style: li_style,642 views_style: li_style,643 downloads_style: li_style,644 comments_style: li_style,645 rating_style: li_style,646 },647 video: {648 autoplay_id: 'AddsALinkSetupVideoPlayerAutoplay',649 auto_resize_id: 'AddsALinkSetupVideoPlayerAutoResize',650// lock_ratio_id: 'AddsALinkSetupVideoPlayerLockRatio',651 fit_aspect_ratio_id: 'AddsALinkSetupVideoPlayerFitAspectRatio',652 height_id: 'AddsALinkSetupVideoPlayerHeight',653 width_id: 'AddsALinkSetupVideoPlayerWidth',654 min_height_id: 'AddsALinkSetupVideoMinResizeHeight',655 min_width_id: 'AddsALinkSetupVideoMinResizeWidth',656 max_height_id: 'AddsALinkSetupVideoMaxResizeHeight',657 max_width_id: 'AddsALinkSetupVideoMaxResizeWidth',658 download_preview_id: 'AddsALinkSetupVideoDownloadPreview',659 download_preview_text_id: 'AddsALinkSetupVideoDownloadPreviewText',660 title_style: 'text-align:center;margin:0 0 5px 0;font-weight:bold;',661 ul_style: ul_style,662 autoplay_style: li_style,663 auto_resize_style: li_style,664// lock_ratio_style: li_style,665 fit_aspect_ratio_style: "margin-left: 10px;",666 height_style: li_style_text,667 width_style: li_style_text,668 min_height_style: li_style_text,669 min_width_style: li_style_text,670 max_height_style: li_style_text,671 max_width_style: li_style_text,672 download_preview_style: li_style,673 download_preview_text_style: indent_3+li_style_base,674 },675 script: {676 check_interval_id: 'AddsALinkSetupScriptCheckInterval',677 check_interval_done_id: 'AddsALinkSetupScriptCheckIntervalDone',678 max_send_request_id: 'AddsALinkSetupScriptMaxSendRequest',679 max_wait_limit_id: 'AddsALinkSetupScriptMaxWaitLimit',680 max_retry_id: 'AddsALinkSetupScriptMaxRetry',681 ul_style: ul_style,682 check_interval_style: li_style_text,683 check_interval_done_style: li_style_text,684 max_send_request_style: li_style_text,685 max_wait_limit_style: li_style_text,686 max_retry_style: li_style_text,687 },688 update: {689 check_now_id: 'AddsALinkSetupCheckNowButton',690 check_now_style: 'position:absolute;right:40px;top:100px;cursor:pointer;background-color:buttonface;',691 type_name: 'AddsALinkSetupUpdateTypeName',692 day_name: 'AddsALinkSetupUpdateDayName',693 no_check_id: 'AddsALinkSetupUpdateNoCheck',694 every_loading_id: 'AddsALinkSetupUpdateEveryLoading',695 once_a_day_id: 'AddsALinkSetupUpdateOnceADay',696 once_a_week_id: 'AddsALinkSetupUpdateOnceAWeek',697 once_a_month_id: 'AddsALinkSetupUpdateOnceAMonth',698 day_box_id: 'AddsALinkSetupUpdateDayBox',699 any_day_id: 'AddsALinkSetupUpdateCheckAnyDay',700 sunday_id: 'AddsALinkSetupUpdateCheckSunday',701 monday_id: 'AddsALinkSetupUpdateCheckMonday',702 tuesday_id: 'AddsALinkSetupUpdateCheckTuesday',703 wednesday_id: 'AddsALinkSetupUpdateCheckWednesday',704 thursday_id: 'AddsALinkSetupUpdateCheckThursday',705 friday_id: 'AddsALinkSetupUpdateCheckFriday',706 saturday_id: 'AddsALinkSetupUpdateCheckSaturday',707 title_style: 'text-align:center;margin:0 0 5px 0;font-weight:bold;',708 ul_style: ul_style,709 day_box_style: 'margin-left:10px;padding-bottom:10px;',710 li_style: li_style,711 },712 radio: {713 style: 'cursor:pointer;margin-right:6px;margin-left:10px;'714 },715 checkbox: {716 style: 'cursor:pointer;margin-right:10px;margin-left:15px;'717 },718 textbox: {719 style: 'margin-left:10px;'720 },721 button: {722 ok_id: 'AddsALinkSetupOKButton',723 cancel_id: 'AddsALinkSetupCancelButton',724 ok_style: 'margin:20px 20px 10px 100px;cursor:pointer;',725 cancel_style: 'margin:20px 0px 10px 100px;cursor:pointer;',726 }727};728729var old_href = '';730var watch_page = false;731var hide_player = false;732var add_download_button = false;733var watch_page_menu_added = false;734var need_username = true;735var player_locked = false;736var last_top = 0;737var last_left = 0;738var last_width = 0;739var last_height = 0;740var last_player_width = 0;741var last_player_height = 0;742var aspect_ratio_locked = false;743var aspect_ratio;744var listener_query = '//div[@id="contentInner"]|//div[@id="contentHolder"]';745var anchor_query = '//div[@id="contentInner"]//a[@class="thumbTitle maxLines2"]|//ul[@class="thumbList"]//a[@class="thumbTitle maxLines2"]';746var cell_query = '../..';747var listbox_query = 'ancestor::div[@id="browseList"]';748var added_query = '..';749750const TYPE_HEIGHT_AUTO = 0;751const TYPE_HEIGHT_CALC = 1;752var cell_calc_type = TYPE_HEIGHT_CALC;753var list_calc_type = TYPE_HEIGHT_AUTO;754755if(window.location.href.indexOf('http://www.veoh.com/videos/') >= 0 ||756 window.location.href.indexOf('http://www.veoh.com/group/') >= 0 ||757 window.location.href.indexOf('http://www.veoh.com/collection/') >= 0 ||758 window.location.href.indexOf('http://www.veoh.com/users/') >= 0 ||759 window.location.href.indexOf('http://www.veoh.com/myprofile/videos') >= 0 ||760 window.location.href.indexOf('http://www.veoh.com/browse/') >= 0 ||761 window.location.href.indexOf('http://www.veoh.com/search/videos') >= 0 ||762 window.location.href.indexOf('/watch/') >= 0 ||763 window.location.href.indexOf('#watch%3D') >= 0) {764 add_download_button = true;765}766if(window.location.href.indexOf('/watch/') >= 0 ||767 window.location.href.indexOf('#watch%3D') >= 0) {768 watch_page = true;769}770771if(window.location.href.indexOf('http://www.veoh.com/myprofile/videos') >= 0) {772 need_username = false;773}774775Init();776777window.addEventListener(778 "load",779 function() {780 if(window.location.href.indexOf('/watch/') >= 0 ||781 window.location.href.indexOf('#watch%3D') >= 0) {782 watch_page = true;783 }784 if(watch_page == true) {785 watch_page_proc();786 if(add_download_button == true) {787 AddDownloadButton();788 }789 }790 if(add_download_button == true) {791 list_page_proc();792793// Watch over the player displayed794 var node = document.getElementById("watch");795 if(node) {796 node.addEventListener(797 "DOMAttrModified",798 AttrModified,799 false);800 }801 }802 },803false);804805function SetNeedInformation() {806 if(custom.list.check_box_option || custom.list.preview_button || custom.list.download_preview ||807 custom.list.username || custom.list.filesize || custom.list.dateAdded || custom.list.views ||808 custom.list.downloads || custom.list.numofcomments || custom.list.rating) {809 need_information = true;810 } else {811 need_information = false;812 }813}814815function WatchOver() {816 check_interval = custom.queue.check_interval;817 if(QueueCheck()) {818 QueueControl();819 }820 setTimeout(WatchOver, check_interval);821}822823function QueueCheck() {824 var sent = 0;825 var received = 0;826 var count = 0;827 var none = 0;828 var done = 0;829 var now = (new Date()).getTime();830 for (var pid in queue) {831 count++;832 switch(queue[pid].stat) {833 case SENT_REQUEST:834 if(now - queue[pid].sent_time < custom.queue.max_wait_limit) {835 sent++;836 } else {837 WaitMessage(pid, -1, "Can't get informations");838 queue[pid].stat = NOT_RECEIVED;839 done++;840 }841 break;842 case RECEIVED_RESPONSE:843 received++;844 break;845 case NONE:846 none++;847 break;848 case STORED_DATA:849 done++;850 break;851 default:852 done++;853 }854 }855 total_queue_num = count;856 current_request_num = sent;857 if(current_request_num < custom.queue.max_send_request) {858 if(none > 0) {859 return true;860 }861 if(total_queue_num > done &&862 retry_count < custom.queue.max_retry) {863 retry_count++;864 for (var pid in queue) {865 switch(queue[pid].stat) {866 case SENT_REQUEST:867 case RECEIVED_RESPONSE:868 case NOT_RECEIVED:869 queue[pid].stat = NONE;870 break;871 }872 }873 return true;874 }875 }876 if(total_queue_num == done && done > 0) {877 check_interval = custom.queue.check_interval_done;878 retry_count = 0;879 }880 return false;881}882883function QueueControl() {884 var sent = current_request_num;885 var now = (new Date()).getTime();886 for (var pid in queue) {887 if(sent >= custom.queue.max_send_request) {888 break;889 }890 if(queue[pid].stat == NONE) {891 GetVideoInformation(pid);892 sent++;893 }894 }895}896897function MakeHtmlForButton(btn_var, link_text) {898 var base_style = buildStyle(custom.style.watch.download, btn_var.div_style);899 var title_style = buildStyle(custom.style.watch.title, btn_var.title_style);900 var anchor_style = buildStyle(custom.style.watch.anchor, btn_var.anchor_style);901902 var html = 903 '<div id="' + btn_var.div_id + '" style="' + base_style + '">' +904 '<span id="' + btn_var.title_id + '" style="' + title_style + '"> </span>' +905 '<span id="' + btn_var.span_id + '" style="' + styles.close + '">' +906 '<a id="' + btn_var.anchor_id + '" href="' + btn_var.download_url + '" style="' + anchor_style + '">'+link_text+'</a>' +907 '</span>';908 if(btn_var.div_id == added_box_watch.original.div_id) {909 html += '<input type="button" id="' + added_box_watch.geturl.id + '" style="display:none;" value="Get URL"></input>';910 }911 html += '</div>';912 return html;913}914915function AddDownloadButton() {916917 var btn_html = MakeHtmlForButton(added_box_watch.original, custom.watch.download_link_text) +918 MakeHtmlForButton(added_box_watch.preview, custom.watch.download_preview_text) +919 MakeHtmlForButton(added_box_watch.mp4, custom.watch.iPhone_text) +920 '<br />';921922// Add detail information box923 // get playerInfo and embedlinkOuter object924 var p = document.getElementById(added_box_watch.base.id);925 if(!p) {926 p = document.createElement('div');927 p.id = added_box_watch.base.id;928 }929930 p.innerHTML = btn_html;931932 var node1, node2;933 node1 = document.getElementById("playerMetaWrapper");934 node2 = document.getElementById("footer");935 if(!node1 && !node2) {936 return; // maybe BUG937 } else {938 var node;939 node1.parentNode.insertBefore(p, node1);940 node = document.getElementById(added_box_watch.geturl.id);941 if(node) {942 node.addEventListener("click",Change,false);943 if(added_box_watch.geturl.show == true) {944 node.setAttribute('style',added_box_watch.geturl.style);945 }946 }947 node = document.getElementById("playerBottom");948 if(node) {949 node.addEventListener(950 "DOMSubtreeModified",951 Video_Changed,952 false);953 }954 Change();955 }956}957958const VIDEO_INFO_URL = 0;959const ORIGINAL_URL = 1;960const IPHONE_URL = 2;961962function buildURL(pid, target) {963 var url = '';964 switch(target) {965 case VIDEO_INFO_URL:966 url = 'http://www.veoh.com/rest/v2/execute.xml?method=veoh.video.findByPermalink&apiKey=4D3E42EC-F10C-4172-A176-D30B468A6972&permalink=' + pid;967 break;968 case ORIGINAL_URL:969 url = 'veoh2://downloadVideo?permalinkId='+pid+'&command=49347A0A-C783-4e92-ADCE-ED7C93207E58';970 break;971 case IPHONE_URL:972 url = 'http://www.veoh.com/iphone/#_Watch/' + pid;973 break;974 }975 return url;976}977978function buildStyle(val, base) {979 var style = '';980 if(base) {981 style += base;982 if(style.substr(base.length-1) != ';') {983 style += ';';984 }985 }986 if(val.text_color) {987 style += "color:"+val.text_color+";";988 }989 if(val.bg_color) {990 style += "background-color:"+val.bg_color+";";991 }992 if(val.bg_image) {993 if(val.bg_image.substr(0, 4) == 'http') {994 style += "background-image:url("+val.bg_image+");";995 } else {996 style += "background-image:"+val.bg_image+";";997 }998 }999 if(val.font_size) {1000 style += "font-size:"+val.font_size+";";1001 }1002 if(val.font_weight) {1003 style += "font-weight:"+val.font_weight+";";1004 }1005 if(val.others) {1006 style += val.others;1007 }1008 return style;1009}10101011function Toggle_Listener(mode) {1012 var node = document.getElementById('contentInner');1013 if(!node) {1014 node = document.getElementById('contentHolder');1015 if(!node) {1016 return;1017 }1018 }1019 if(mode) {1020 node.addEventListener("DOMNodeInserted",NodeInserted,false);1021 } else {1022 node.removeEventListener("DOMNodeInserted",NodeInserted,false);1023 }1024}10251026function NodeInserted() {1027 list_page_proc();1028 if(load_thumbnails) {1029 var images = document.getElementsByClassName('lazyLoad');1030 for(var i = 0; i < images.length; i++) {1031 images[i].src = images[i].getAttribute('_src');1032 }1033 }1034}10351036function list_page_proc() {1037 SetNeedInformation();1038 AddDownloadCheckBox();10391040}10411042function AddDownloadCheckBox() {1043 var q = anchor_query;1044 var xp = document.evaluate(q, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);1045 if(xp.snapshotLength) {10461047 for (var i=0; i < xp.snapshotLength; i++) {1048 var anchor = xp.snapshotItem(i);1049 if(/\/watch\/.*/.test(anchor.href) == false) {1050 continue;1051 }1052 var pid = anchor.href.match(/\/watch\/(.*)/)[1];1053 var parent = document.evaluate(added_query, anchor, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;1054 if(queue[pid]) {1055 if(document.getElementById(added_box.base.id + pid)) {1056 continue;1057 }1058 queue[pid] = {};1059 }1060 var video_cell = document.evaluate(cell_query, anchor, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;1061 var list_box = null;1062 if(listbox_query) {1063 list_box = document.evaluate(listbox_query, anchor, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;1064 }10651066 var base = document.createElement('div');1067 base.id = added_box.base.id + pid;1068 var style = buildStyle(custom.style.list.base, added_box.base.style);1069 base.setAttribute('style', style);1070 if(need_username == false) {1071 base.innerHTML = '<br />';1072 }10731074 Toggle_Listener(false);1075 parent.appendChild(base);1076 Toggle_Listener(true);10771078 queue[pid] = {1079 stat: NONE,1080 node: base,1081 parent: parent,1082 offsetHeight: base.parentNode.parentNode.offsetHeight,1083 video_cell: video_cell,1084 list_box: list_box,1085 offsetTop: video_cell.offsetTop,1086 offsetHeight: parent.offsetHeight,1087 offsetTop: video_cell.offsetTop,1088 cell_offsetHeight: video_cell.offsetHeight,1089 cell_calc_type: cell_calc_type,1090 list_calc_type: list_calc_type,1091 };1092// AddCheckBox(pid);1093 }10941095 AddButtonBox();1096 ChangeButtonBoxMode(added_buttons.top.id, custom.list.check_box_option)1097 ChangeButtonBoxMode(added_buttons.bottom.id, custom.list.check_box_option)1098 } else {1099 Toggle_Listener(true);1100 }1101}11021103function ChangeButtonBoxMode(id, mode) {1104 var div = document.getElementById(id);1105 if(!div) return; // perhaps bug11061107 Toggle_Listener(false);11081109 if(id == added_buttons.top.id) {1110 if(mode == true) {1111 div.setAttribute('style', added_buttons.top.style);1112 } else {1113 div.setAttribute('style', added_buttons.top.style+styles.close);1114 }1115 } else1116 if(id == added_buttons.bottom.id) {1117 if(mode == true) {1118 div.setAttribute('style', added_buttons.bottom.style);1119 } else {1120 div.setAttribute('style', added_buttons.bottom.style+styles.close);1121 }1122 }11231124 Toggle_Listener(true);1125}11261127function AddButtonBox() {1128 var id = added_buttons.top.id;1129 var div = document.getElementById(id);1130 if(div) { // Already exists1131 return;1132 }11331134 Toggle_Listener(false);11351136 var q = '//ul[@id="browseList"]|//ul[@id="groupVideoThumbList"]|//ul[@class="thumbList"]';1137 xp = document.evaluate(q, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);1138 var parent = xp.snapshotItem(0);11391140 var div = document.createElement('div');1141 div.id = added_buttons.top.id;1142 div.setAttribute('style', added_buttons.top.style);11431144 var div2 = document.createElement('div');1145 div2.id = added_buttons.bottom.id;1146 div2.setAttribute('style', added_buttons.bottom.style);1147// buttons1148// Select All1149 var btn1 = document.createElement('input');1150 btn1.type = 'button';1151// btn1.id = added_buttons.select.id;1152 btn1.value = 'Select All';1153 var style = buildStyle(custom.style.list.download_buttons, added_buttons.select.style);1154 btn1.setAttribute('style', style);1155 btn1.addEventListener("click",function(){SetAllCheckbox(true);},false);1156 var btn1_2 = btn1.cloneNode(false);1157 btn1_2.addEventListener("click",function(){SetAllCheckbox(true);},false);1158 div.appendChild(btn1);1159 div2.appendChild(btn1_2);11601161// Clear All1162 var btn2 = document.createElement('input');1163 btn2.type = 'button';1164// btn2.id = added_buttons.clear.id;1165 btn2.value = 'Clear All';1166 style = buildStyle(custom.style.list.download_buttons, added_buttons.clear.style);1167 btn2.setAttribute('style', style);1168 btn2.addEventListener("click",function(){SetAllCheckbox(false);},false);1169 var btn2_2 = btn2.cloneNode(false);1170 btn2_2.addEventListener("click",function(){SetAllCheckbox(false);},false);1171 div.appendChild(btn2);1172 div2.appendChild(btn2_2);11731174// Download Original videos1175 var btn3 = document.createElement('input');1176 btn3.type = 'button';1177// btn3.id = added_buttons.download.id;1178 btn3.value = 'Download selected videos';1179 var style = buildStyle(custom.style.list.download_buttons, added_buttons.download.style);1180 btn3.setAttribute('style', style);1181 btn3.addEventListener("click",DownloadOriginal,false);1182 var btn3_2 = btn3.cloneNode(false);1183 btn3_2.addEventListener("click",DownloadOriginal,false);1184 div.appendChild(btn3);1185 div2.appendChild(btn3_2);118611871188 parent.parentNode.insertBefore(div, parent);1189 parent.parentNode.appendChild(div2);11901191 Toggle_Listener(true);1192}11931194function SetAllCheckbox(check) {1195 var nodes = document.getElementsByClassName('original_download');1196 for(var i = 0; i < nodes.length; i++) {1197 nodes[i].checked = check;1198 }1199}12001201function DownloadOriginal() {1202 var nodes = document.getElementsByClassName('original_download');1203 for(var i = 0; i < nodes.length; i++) {1204 if(nodes[i].checked == true) {1205 var pid = nodes[i].value;1206 window.location.href = buildURL(pid, ORIGINAL_URL);1207 }1208 }1209}12101211function ModifyFileName(filename) {1212 filename = filename.replace(/[\\\/:;\*\?\"<>\|]/g,'_');1213 if(filename.replace('.', '') == '') {1214 filename = filename.replace(/\./g, '_');1215 }1216 return filename;1217}121812191220function watch_page_proc() {1221 if(document.getElementById(added_box_watch.info.parent_id)) return;12221223 var info_html = 1224 '<div id="'+added_box_watch.info.caption_id+'" style="'+styles.close+'">Original Video Information ' +1225 '<input type="button" id="' + added_box_watch.info.btn_id + '" style="' + added_box_watch.info.btn_style + 1226 '" value="Open Video Information"></input>'+1227 '</div>'+1228 '<div id="'+added_box_watch.info.box_id+'" style="'+styles.close+'"></div>';122912301231// Add detail information box1232 // get playerInfo and embedlinkOuter object1233 var p = document.createElement('div');12341235 p.innerHTML = info_html;1236 p.setAttribute('id', added_box_watch.info.parent_id);1237 p.setAttribute('style', styles.close);12381239 var node1, node2;1240 node1 = document.getElementById("playerMetaWrapper");1241 node2 = document.getElementById("footer");1242 if(!node1 && !node2) {1243 return; // maybe BUG1244 } else {1245 var node;1246 node2.parentNode.insertBefore(p, node2);1247 node = document.getElementById(added_box_watch.info.btn_id);1248 if(node) {1249 node.addEventListener("click",VideoInfoBox,false);1250 }1251 }1252}12531254// for list page1255function GetSetupDataListPage(){1256 custom.list = GetGMValue("list_page", custom.list, null);1257}12581259function SetSetupDataListPage(){1260 GM_setValue("list_page", uneval(custom.list));1261}12621263// for video panel1264function GetSetupDataVideoPanel(){1265 custom.player = GetGMValue("player", custom.player, null);1266}12671268function SetSetupDataVideoPanel(){1269 GM_setValue("player", uneval(custom.player));1270}12711272// for watch page1273function GetSetupDataWatchPage(){1274 custom.watch = GetGMValue("watch_page", custom.watch, null);1275}12761277function SetSetupDataWatchPage(){1278 GM_setValue("watch_page", uneval(custom.watch));1279}12801281// for update check1282function GetSetupDataUpdateCheck(){1283 update_check = GetGMValue("update_check", update_check, null);1284}12851286function SetSetupDataUpdateCheck(){1287 GM_setValue("update_check", uneval(update_check));1288}12891290// for script control1291function GetSetupDataScriptControl(){1292 custom.queue = GetGMValue("queue", custom.queue, null);1293}12941295function SetSetupDataScriptControl(){1296 GM_setValue("queue", uneval(custom.queue));1297}12981299// style setup data1300function GetSetupDataStyle(){1301 custom.style.list = GetGMValueStyle("style_list", custom.style.list);1302 custom.style.watch = GetGMValueStyle("style_watch", custom.style.watch);1303 custom.style.video_panel = GetGMValueStyle("style_video_panel", custom.style.video_panel);1304}13051306function SetSetupDataStyle(){1307 GM_setValue("style_list", uneval(custom.style.list));1308 GM_setValue("style_watch", uneval(custom.style.watch));1309 GM_setValue("style_video_panel", uneval(custom.style.video_panel));1310}13111312// others setup data1313function GetSetupDataOthers(){1314}13151316function SetSetupDataOthers(){1317}13181319// setup data version1320function GetSetupDataVersion(){1321 custom.setup_version = GM_getValue("setup_version", custom.setup_version);1322 if(custom.setup_version < SETUP_VERSION) {1323 ConvertSetupData();1324 }1325}13261327function SetSetupDataVersion(){1328 GM_setValue("setup_version", SETUP_VERSION);1329}13301331// all set up data except version1332function GetSetupDataAll() {1333 GetSetupDataListPage();1334 GetSetupDataVideoPanel();1335 GetSetupDataWatchPage();1336 GetSetupDataUpdateCheck();1337 GetSetupDataScriptControl();1338 GetSetupDataStyle();1339 GetSetupDataOthers();1340}13411342function SetSetupDataAll() {1343 SetSetupDataVersion()1344 SetSetupDataListPage();1345 SetSetupDataVideoPanel();1346 SetSetupDataWatchPage();1347 SetSetupDataUpdateCheck();1348 SetSetupDataScriptControl();1349 SetSetupDataStyle();1350 SetSetupDataOthers();1351}13521353// for setup data conversion1354function ConvertSetupData(){1355 if(custom.setup_version == 0) { // old format data1356// for watch page1357 custom.watch.image_url = GM_getValue("image_url", custom.watch.image_url);1358 if(custom.watch.image_url) { // for old version user1359 custom.watch.disp_type = IMAGE_TYPE;1360 } else {1361 custom.watch.disp_type = TEXT_TYPE;1362 }1363 custom.watch.disp_type = GM_getValue('disp_type',custom.watch.disp_type);13641365 custom.watch.image_text = GM_getValue("image_text", custom.watch.image_text);1366 if(!custom.watch.image_text) { // for old version user1367 custom.watch.image_text = custom.watch.text_color;1368 }1369 custom.watch.bg_color = GM_getValue("bg_color", custom.watch.bg_color);1370 custom.watch.text_color = GM_getValue("text_color", custom.watch.text_color);1371 custom.watch.detail_information = GM_getValue("show_video_detail_information", custom.watch.detail_information);1372 custom.watch.meta_data_option = GM_getValue("add_meta_data_option", custom.watch.meta_data_option);1373 custom.list.check_box_option = GM_getValue("add_check_box_option", custom.list.check_box_option);1374 custom.watch.convert_utf8 = GM_getValue("convert_utf8", custom.watch.convert_utf8);1375// for list page1376 custom.list.username = GM_getValue("add_username", custom.list.username);1377 custom.list.filesize = GM_getValue("add_filesize", custom.list.filesize);1378 custom.list.dateAdded = GM_getValue("add_dateAdded", custom.list.dateAdded);1379 custom.list.views = GM_getValue("add_views", custom.list.views);1380 custom.list.downloads = GM_getValue("add_downloads", custom.list.downloads);1381 custom.list.numofcomments = GM_getValue("add_numofcomments", custom.list.numofcomments);1382 custom.list.rating = GM_getValue("add_rating", custom.list.rating);1383 custom.list.preview_button = GM_getValue("add_preview_button", custom.list.preview_button);1384 custom.list.download_preview = GM_getValue("add_download_preview", custom.list.download_preview);1385// for video panel1386 custom.player.autoplay = GM_getValue("autoplay_list", custom.player.autoplay);1387 custom.player.auto_resize = GM_getValue("auto_resize", custom.player.auto_resize);1388 custom.player.min_width = GM_getValue("min_width_list", custom.player.min_width);1389 custom.player.min_height = GM_getValue("min_height_list", custom.player.min_height);1390 custom.player.max_width = GM_getValue("max_width_list", custom.player.max_width);1391 custom.player.max_height = GM_getValue("max_height_list", custom.player.max_height);1392 custom.player.player_height = GM_getValue("player_height_list", custom.player.player_height);1393 custom.player.player_width = GM_getValue("player_width_list", custom.player.player_width);1394 custom.player.lock_ratio = GM_getValue("lock_ratio", custom.player.lock_ratio);13951396 } else {1397 GetSetupDataAll();1398 }1399 ConvOldDataToNewData(custom.setup_version);1400 DeleteOldData(custom.setup_version);1401 SetSetupDataAll();14021403}14041405function GetGMValueStyle(key, val){1406 var old_data = GetGMValue(key, val, null);1407 for(var i in val) {1408 if(old_data[i]) {1409 for(var j in old_data[i]) {1410 if(old_data[i][j]) {1411 val[i][j] = old_data[i][j];1412 }1413 }1414 }1415 }1416 return val;1417}14181419function GetGMValue(key, val, ignores) {1420 if(typeof val == "object") {1421 var old_data = eval(GM_getValue(key, val));1422 for(var i in old_data) {1423 if(ignores) {1424 if(ignores.indexOf(i) >= 0) {1425 continue;1426 }1427 }1428 val[i] = old_data[i];1429 }1430 } else {1431 val = GM_getValue(key, val);1432 }1433 return val;1434}143514361437function ConvOldDataToNewData(old_version) {1438 if(old_version < 4) { // from 1 to 31439 if(custom.watch.disp_type == TEXT_TYPE) {1440 custom.style.watch.anchor.text_color = custom.watch.text_color;1441 custom.style.watch.anchor.bg_color = custom.watch.bg_color;1442 custom.style.watch.anchor.bg_image = "";1443 } else {1444 custom.style.watch.anchor.text_color = custom.watch.image_text;1445 custom.style.watch.anchor.bg_color = custom.watch.bg_color;1446 custom.style.watch.anchor.bg_image = custom.watch.image_url;1447 }14481449 delete custom.watch.disp_type;1450 delete custom.watch.text_color;1451 delete custom.watch.bg_color;1452 delete custom.watch.image_url;1453 delete custom.watch.image_text;1454 }1455}14561457function DeleteOldData(old_version) {1458 if(typeof GM_deleteValue != "function") return;1459 if(old_version == 0) { // old format data1460// for list page1461 GM_deleteValue("add_check_box_option");1462 GM_deleteValue("add_preview_button");1463 GM_deleteValue("add_download_preview");1464 GM_deleteValue("add_username");1465 GM_deleteValue("add_filesize");1466 GM_deleteValue("add_dateAdded");1467 GM_deleteValue("add_views");1468 GM_deleteValue("add_downloads");1469 GM_deleteValue("add_numofcomments");1470 GM_deleteValue("add_rating");1471// for watch page1472 GM_deleteValue("disp_type");1473 GM_deleteValue("text_color");1474 GM_deleteValue("bg_color");1475 GM_deleteValue("image_url");1476 GM_deleteValue("image_text");1477 GM_deleteValue("show_video_detail_information");1478 GM_deleteValue("add_meta_data_option");1479 GM_deleteValue("convert_utf8");1480// for video panel1481 GM_deleteValue("autoplay_list");1482 GM_deleteValue("auto_resize");1483 GM_deleteValue("player_width_list");1484 GM_deleteValue("player_height_list");1485 GM_deleteValue("min_width_list");1486 GM_deleteValue("min_height_list");1487 GM_deleteValue("max_width_list");1488 GM_deleteValue("max_height_list");1489// for others1490 GM_deleteValue("Interval");1491 }1492}14931494// initialize1495function Init() {1496// get setup data1497 GetSetupDataVersion();1498 GetSetupDataAll();14991500// Add menu1501 if(add_download_button == true) {1502 GM_registerMenuCommand( "#### Set up this script(Veoh) ####", Setup);1503 }15041505// for update check1506 UpdateCheck(false);15071508 WatchOver();15091510}15111512var old_display = '';15131514function AttrModified() {1515 var node = document.getElementById("watch");1516 if(node) {1517 if(node.style.display == 'block') {1518 watch_page = true;1519 if(old_display == '') {1520 old_display = 'block';1521 watch_page_proc();1522 AddDownloadButton();1523 }1524 } else {1525 watch_page = false;1526 old_display = '';1527 }1528 }1529}15301531function Video_Changed() {15321533 var old_permalink = permalink;1534 if(Get_Permalink()) {1535 if(old_permalink != permalink) {1536 setTimeout(Change, 1);1537// Change();1538 old_href = window.location.href;1539 }1540 }1541}15421543function Get_Permalink() {15441545 var dl_link = document.getElementById("watchDownload");1546 if(dl_link) {1547 var href = dl_link.getAttribute("href");1548 if(href.match(/permalinkId\/(.*)/)) {1549 permalink = RegExp.$1;1550 return true;1551 }1552 }1553 var inputtags = document.getElementsByTagName("input");1554 if(!inputtags) {1555 permalink = "";1556 return false;1557 }1558 var i;1559 var embedurl = '';1560 for(i = 0; i < inputtags.length; i++) {1561 var class = inputtags[i].getAttribute("class");1562 if(class != 'embedinputlarge' && class != 'embedinput') {1563 continue;1564 }1565 embedurl = inputtags[i].getAttribute("value");1566 break;1567 }1568 if(!embedurl) return false;1569 var p = embedurl.match(/\/watch\/(.*)/);1570 if(p) {1571 permalink = RegExp.$1;1572 if(permalink.match(/#watch%3D(.*)/) ){1573 permalink = RegExp.$1;1574 }1575 } else if(window.location.href.match(/#watch%3D(.*)/) ) {1576 permalink = RegExp.$1;1577 }15781579 return true;1580}15811582var utf8conv = new Array("tags","title","description","embedCode");1583var max_loop = 5;1584var videoInfo = {};15851586// Parse source xml1587function ParseSourceXml(text)1588{1589 var parser = new DOMParser();1590 var xml = parser.parseFromString( text, "text/xml" );15911592 var video_node = xml.getElementsByTagName('video');1593 if(!video_node.length) {1594 return null;1595 }15961597 var attributes = video_node[0].attributes;1598 for(var i = 0; i < attributes.length; i++) {1599 key = attributes[i].name;1600 videoInfo[key] = attributes[i].value;16011602 if(custom.watch.convert_utf8) {1603// Change character code to utf81604 if(utf8conv.indexOf(key) >= 0 && _is_utf8(videoInfo[key]) == true) {1605 var str = _from_utf8(videoInfo[key]);1606// re-convert up to max_loop while the string code is UTF-81607 for(var loop = 0; loop < max_loop; loop++) {1608 if(_is_utf8(str) == true) str = _from_utf8(str);1609 else break;1610 }1611 videoInfo[key] = str;1612 }1613 }16141615 }1616 videoInfo['video_width'] = DEFAULT_PLAYER_WIDTH;1617 videoInfo['video_height'] = DEFAULT_PLAYER_HEIGHT;1618 if(videoInfo['embedCode']) {1619 videoInfo['embedCode'] = decodeURI(videoInfo['embedCode'].replace(/&lt;/g,'<').replace(/&gt;/g,'>'));1620 } else if(videoInfo['aowEmbedCode']) {1621 videoInfo['embedCode'] = decodeURI(videoInfo['aowEmbedCode'].replace(/&lt;/g,'<').replace(/&gt;/g,'>'));1622 }1623 if(videoInfo['embedCode']) {1624 var div = document.createElement('div');1625 div.innerHTML = videoInfo['embedCode'];1626 var embed = div.firstChild;1627 if(embed) {1628 var width = embed.getAttribute('width');1629 var height = embed.getAttribute('height');1630 if(width) {1631 videoInfo['video_width'] = width;1632 }1633 if(height) {1634 videoInfo['video_height'] = height;1635 }1636 }1637 }1638 return videoInfo;16391640}16411642function addMetaInfo() {1643 var brother = document.getElementById('ratingStars');1644 var id1;1645 var id2;1646 var node1;1647 var node2;1648 var style;1649 if(custom.watch.meta_data_option == true) {1650 if(videoInfo['rating'] && videoInfo['numRatingVotes']) {1651 id1 = added_box_watch.meta.rating_dt_id;1652 id2 = added_box_watch.meta.rating_dd_id;1653 node1 = document.getElementById(id1);1654 node2 = document.getElementById(id2);1655 if(!node1 && !node2) {1656 var dt = document.createElement('dt');1657 var dd = document.createElement('dd');1658 dt.id = id1;1659 dd.id = id2;1660 dt.innerHTML = '';1661 dd.innerHTML = videoInfo['rating']+' ('+videoInfo['numRatingVotes']+')';1662 dt.setAttribute('class', 'numRatingVotes');1663 dd.setAttribute('class', 'numRatingVotes');1664 style = buildStyle(custom.style.watch.meta, added_box_watch.meta.rating_dt_style);1665 dt.setAttribute('style', style);1666 style = buildStyle(custom.style.watch.meta, added_box_watch.meta.rating_dd_style);1667 dd.setAttribute('style', style);1668 brother.parentNode.appendChild(dt);1669 brother.parentNode.appendChild(dd);1670 } else {1671 node2.innerHTML = videoInfo['rating']+' ('+videoInfo['numRatingVotes']+')';1672 }1673 }1674 if(videoInfo['numDownloads']) {1675 id1 = added_box_watch.meta.downloads_dt_id;1676 id2 = added_box_watch.meta.downloads_dd_id;1677 node1 = document.getElementById(id1);1678 node2 = document.getElementById(id2);1679 if(!node1 && !node2) {1680 var dt = document.createElement('dt');1681 var dd = document.createElement('dd');1682 dt.id = id1;1683 dd.id = id2;1684 dt.innerHTML = 'downloads:';1685 dd.innerHTML = videoInfo['numDownloads'];1686 dt.setAttribute('class', 'numDownloads');1687 dd.setAttribute('class', 'numDownloads');1688 style = buildStyle(custom.style.watch.meta, added_box_watch.meta.downloads_dt_style);1689 dt.setAttribute('style', style);1690 style = buildStyle(custom.style.watch.meta, added_box_watch.meta.downloads_dd_style);1691 dd.setAttribute('style', style);1692 brother.parentNode.appendChild(dt);1693 brother.parentNode.appendChild(dd);1694 } else {1695 node1.innerHTML = 'downloads:';1696 node2.innerHTML = videoInfo['numDownloads'];1697 }1698 }1699 } else {1700 id1 = added_box_watch.meta.rating_dt_id;1701 id2 = added_box_watch.meta.rating_dd_id;1702 node1 = document.getElementById(id1);1703 node2 = document.getElementById(id2);1704 if(node1) {1705 brother.parentNode.removeChild(node1);1706 }1707 if(node2) {1708 brother.parentNode.removeChild(node2);1709 }1710 id1 = added_box_watch.meta.downloads_dt_id;1711 id2 = added_box_watch.meta.downloads_dd_id;1712 node1 = document.getElementById(id1);1713 node2 = document.getElementById(id2);1714 if(node1) {1715 brother.parentNode.removeChild(node1);1716 }1717 if(node2) {1718 brother.parentNode.removeChild(node2);1719 }1720 }1721}17221723function AddInfomation() {1724 var originalVideoInfo = {};1725 var makeAnchors = [1726 'fullPreviewHashPath',1727 'fullPreviewHashLowPath',1728 'previewUrl',1729// 'ipodUrl',1730 'highResImage',1731 'medResImage',1732 'fullMedResImagePath',1733 'fullHighResImagePath'1734 ];17351736 var info_html = '<table border="1" cellpadding="2">';1737 for(var key in videoInfo) {1738 info_html = info_html + '<tr>';1739 info_html = info_html + '<td align="left">'+key+'</td>';1740// Add anchor1741 if(makeAnchors.indexOf(key) >= 0) {1742 originalVideoInfo[key] = videoInfo[key];1743 videoInfo[key] = '<a href="' + videoInfo[key] + '">'+videoInfo[key]+'</a>';1744 }1745// Disable embed1746 if(key == 'embedCode' || key == 'aowEmbedCode') {1747 videoInfo[key] = videoInfo[key].replace(/\</g, '&lt;').replace(/\>/g, '&gt;');1748 }1749 info_html = info_html + '<td align="left">'+videoInfo[key]+'</td>';1750 info_html = info_html + '</tr>';1751 }1752 info_html = info_html + '</table>';17531754 var info_node = document.getElementById(added_box_watch.info.box_id);1755 if(info_node) {1756 info_node.innerHTML = info_html;1757 }17581759 addMetaInfo();17601761 if(videoInfo['isExternalMedia'] == 'true') {1762 GM_log("ExternalMedia text:"+text);1763 ExternalMedia();1764 return;1765 }17661767 added_box_watch.original.download_url = buildURL(videoInfo['permalinkId'], ORIGINAL_URL);1768 if(originalVideoInfo['previewUrl']) {1769 added_box_watch.preview.download_url = originalVideoInfo['previewUrl'];1770 } else 1771 if(originalVideoInfo['fullPreviewHashPath']) {1772 added_box_watch.preview.download_url = originalVideoInfo['fullPreviewHashPath'];1773 } else 1774 if(originalVideoInfo['fullPreviewHashLowPath']) {1775 added_box_watch.preview.download_url = originalVideoInfo['fullPreviewHashLowPath'];1776 }1777// if(originalVideoInfo['ipodUrl']) {1778// added_box_watch.mp4.download_url = originalVideoInfo['ipodUrl'];1779// }1780 added_box_watch.mp4.download_url = buildURL(permalink, IPHONE_URL);17811782 var title_span;1783 var dl_span;1784 var dl_node;1785 var base_node;1786 if(added_box_watch.original.download_url) {1787 title_span = document.getElementById(added_box_watch.original.title_id);1788 if(title_span) {1789 if(videoInfo['primaryCollectionTitle']) {1790 title_span.innerHTML = videoInfo['primaryCollectionTitle']+' '+videoInfo['title']+videoInfo['origExtension'];1791 } else {1792 title_span.innerHTML = videoInfo['title']+videoInfo['origExtension'];1793 }1794 }1795 dl_span = document.getElementById(added_box_watch.original.span_id);1796 if(dl_span) {1797 dl_span.setAttribute('style', styles.inline_open);1798 }1799 dl_node = document.getElementById(added_box_watch.original.anchor_id);1800 if(dl_node) {1801 if(!dl_node.getAttribute("href")) {1802 dl_node.addEventListener("click", function(e) {1803 e.preventDefault();1804 window.location.href = this.href;1805 return false;1806 },false); 1807 }1808 dl_node.setAttribute("href", added_box_watch.original.download_url);1809 }1810// base_node = document.getElementById(added_box_watch.original.div_id);1811// if(custom.watch.download_original) {1812// base_node.style.display = "block";1813// } else {1814// base_node.style.display = "none";1815// }1816 }1817 if(added_box_watch.preview.download_url) {1818 title_span = document.getElementById(added_box_watch.preview.title_id);1819 if(title_span) {1820 title_span.innerHTML = videoInfo['title']+videoInfo['previewExtension'];1821 }1822 dl_span = document.getElementById(added_box_watch.preview.span_id);1823 if(dl_span) {1824 dl_span.setAttribute('style', styles.inline_open);1825 }1826 dl_node = document.getElementById(added_box_watch.preview.anchor_id);1827 if(dl_node) {1828 dl_node.setAttribute("href", added_box_watch.preview.download_url);1829 }1830// base_node = document.getElementById(added_box_watch.preivew.div_id);1831// if(custom.watch.download_preview) {1832// base_node.style.display = "block";1833// } else {1834// base_node.style.display = "none";1835// }1836 }1837 if(added_box_watch.mp4.download_url) {1838 title_span = document.getElementById(added_box_watch.mp4.title_id);1839 if(title_span) {1840 title_span.innerHTML = '<br />';1841 }1842 dl_span = document.getElementById(added_box_watch.mp4.span_id);1843 if(dl_span) {1844 dl_span.setAttribute('style', styles.inline_open);1845 }1846 dl_node = document.getElementById(added_box_watch.mp4.anchor_id);1847 if(dl_node) {1848 dl_node.setAttribute("href", added_box_watch.mp4.download_url);1849 }1850// base_node = document.getElementById(added_box_watch.mp4.div_id);1851// if(custom.watch.iPhone) {1852// base_node.style.display = "block";1853// } else {1854// base_node.style.display = "none";1855// }1856 }18571858}18591860function CannotGetVideoInfo() {1861 var info_html = 1862 '<table border="1" cellpadding="2">' +1863 '<tr><td>Can'+"'"+'t get the video information</td></tr>' +1864 '</table>';18651866 OutputErrorMessage(info_html);1867}18681869function ExternalMedia() {1870 var info_html = 1871 '<table border="1" cellpadding="2">' +1872 '<tr><td>This video is an external media</td></tr>' +1873 '</table>';18741875 OutputErrorMessage(info_html);1876}18771878function OutputErrorMessage(info_html) {1879 var info_node = document.getElementById(added_box_watch.info.box_id);1880 if(info_node) {1881 added_box_watch.info_node.innerHTML = info_html;1882 }1883 var title_span = document.getElementById(added_box_watch.original.title_id);1884 if(title_span) {1885 title_span.innerHTML = info_html;1886 }1887 var dl_span = document.getElementById(added_box_watch.original.span_id);1888 if(dl_span) {1889 dl_span.setAttribute('style', styles.close);1890 }1891}18921893function Change() {1894 if(window.location.href.indexOf('http://www.veoh.com/group/') >= 0 &&1895 window.location.href.indexOf('#watch%3D') < 0 &&1896 window.location.href.indexOf('/watch/') < 0) {1897 return;1898 }1899 var node = document.getElementById(added_box_watch.info.caption_id);1900 var node2 = document.getElementById(added_box_watch.info.parent_id);1901 if(node2) {1902 if(window.location.href.indexOf('/watch/') >= 0 ||1903 window.location.href.indexOf('#watch%3D') >= 0) {1904 node2.setAttribute('style', styles.inline_open);1905 }1906 }1907 if(node) {1908 node.setAttribute('style', styles.inline_open);1909 if(custom.watch.detail_information == true) {1910 openVideoInformation = false;1911 } else {1912 openVideoInformation = true;1913 }1914 VideoInfoBox();1915 }1916 if(Get_Permalink()) {1917 GetSourceXml();1918 ChangeStyle();1919 } else {1920 GM_log("Change CannotGetVideoInfo window.location.href:"+window.location.href);1921 CannotGetVideoInfo();1922 }1923}19241925function VideoInfoBox() {1926 if(openVideoInformation == true) {1927 Change_Information_Box(styles.close);1928 } else {1929 Change_Information_Box(styles.block_open);1930 }1931}19321933// Get source xml1934function GetSourceXml()1935{1936 var url = buildURL(permalink, VIDEO_INFO_URL);19371938 setTimeout(function(){1939 GM_xmlhttpRequest({1940 method:"GET",1941 url: url,1942 headers:{1943 "User-Agent":"veohplugin-1.1.2 service (NT 5.0; IE 7.0; en-US Windows)",1944 "Accept":"*/*",1945 "Accept-Language":"en-us"1946 },1947 onload: function(xhr){1948 var text = xhr.responseText;1949 if ( xhr.status != 200 ) { // failed1950 GM_log(xhr.status + ': ' + text);1951 CannotGetVideoInfo();1952 return;1953 }1954 var VideoInfo = ParseSourceXml(text);1955 if(VideoInfo) {1956 AddInfomation();1957 } else {1958 GM_log("CannotGetVideoInfo text:"+text);1959 CannotGetVideoInfo();1960 }1961 }1962 });1963 },0);1964}196519661967function GetVideoInformation(pid) {1968 if(!need_information) {1969 return;1970 }19711972 var url = buildURL(pid, VIDEO_INFO_URL);1973 var infoKeys = [1974// 'videoId',1975 'username',1976 'size',1977// 'tags',1978// 'fileHash',1979 'originalHash',1980 'origExtension',1981 'previewHash',1982 'previewExtension',1983 'previewUrl',1984 'embedCode',1985 'title',1986// 'description',1987 'numDownloads',1988 'views',1989 'rating',1990 'numRatingVotes',1991// 'compressor',1992// 'age',1993 'dateAdded',1994// 'country',1995// 'language',1996 'numOfComments',1997 'video_width',1998 'video_height'1999 ];20002001 setTimeout(function(){2002 queue[pid].stat = SENT_REQUEST;2003 queue[pid].sent_time = (new Date()).getTime();2004 WaitMessage(pid, 1);2005 GM_xmlhttpRequest({2006 pid: pid,2007 method:"GET",2008 url: url,2009 headers:{2010 "User-Agent":"veohplugin-1.1.2 service (NT 5.0; IE 7.0; en-US Windows)",2011 "Accept":"*/*",2012 "Accept-Language":"en-us"2013 },2014 onload: function(xhr){2015 var text = xhr.responseText;2016 var pid = this.pid;2017 queue[pid].stat = RECEIVED_RESPONSE;2018 if ( xhr.status != 200 ) { // failed2019 GM_log(xhr.status + ': ' + text);2020 WaitMessage(pid, xhr.status);2021 return;2022 }2023 var VideoInfo = ParseSourceXml(text);2024 if(VideoInfo) {2025 for (var i in infoKeys) {2026 if(VideoInfo[infoKeys[i]]) {2027 queue[pid][infoKeys[i]] = VideoInfo[infoKeys[i]];2028 } else {2029 queue[pid][infoKeys[i]] = "";2030 }2031 }2032 queue[pid].stat = STORED_DATA;2033 WaitMessage(pid, 0);2034 AddMetaData(pid);2035 }2036 }2037 });2038 },0);2039}20402041function AddCheckBox(pid) {2042// Toggle_Listener(false);2043 var id = added_box.chkbox.id+pid;2044 var node = document.getElementById(id);2045 if(!node) {2046 node = document.createElement('input');2047 node.id = id;2048 node.setAttribute('class', 'original_download');2049 node.type = 'checkbox';2050 node.value = pid;2051 queue[pid].node.appendChild(node);2052 }2053 node.checked = false;2054 if(custom.list.check_box_option) {2055 node.setAttribute('style', added_box.chkbox.style);2056 } else {2057 node.setAttribute('style', added_box.chkbox.style + styles.close);2058 }20592060 id = added_box.download.id+pid;2061 var download = document.getElementById(id);2062 if(!download) {2063 download = document.createElement('a');2064 download.id = id;2065 download.addEventListener("click", function(e) {2066 e.preventDefault();2067 window.location.href = this.href;2068 return false;2069 },false); 2070 download.href = buildURL(pid, ORIGINAL_URL);2071 queue[pid].node.appendChild(download);2072 }2073 if(queue[pid].stat == STORED_DATA) {2074 if(queue[pid]['origExtension']) {2075 download.innerHTML = custom.list.download_link_text + '('+queue[pid]['origExtension'].substr(1)+')<br />';2076 }2077// } else {2078// download.innerHTML = custom.list.download_link_text+'<br />';2079 }2080 var style = buildStyle(custom.style.list.download_link, added_box.download.style);2081 if(custom.list.check_box_option) {2082 download.setAttribute('style', style);2083 } else {2084 download.setAttribute('style', style + styles.close);2085 }2086// Toggle_Listener(true);20872088}20892090function WaitMessage(pid, mode) {2091 var id = added_box.meta.wait_id + pid;2092 var div = document.getElementById(id);20932094 Toggle_Listener(false);2095 if(mode == 1) {2096 if(!div) {2097 div = document.createElement('div');2098 div.id = id;2099 div.innerHTML = 'Wait!';2100 var style = buildStyle(custom.style.list.wait, added_box.meta.wait_style);2101 div.setAttribute('style', style);2102 queue[pid].node.appendChild(div);2103 }2104 } else if(mode == 0) {2105 if(div) {2106 div.parentNode.removeChild(div);2107 }2108 } else {2109 if(div) {2110 div.innerHTML = 'Error status:'+mode;2111 }2112 }2113 Toggle_Listener(true);2114}21152116function OpenTooltip(x, y, msg) {2117 var tooltip = document.getElementById(added_box.tooltip.id);2118 if(!tooltip) {2119 tooltip = document.createElement('div');2120 tooltip.id = added_box.tooltip.id;2121 }2122 tooltip.setAttribute('style', added_box.tooltip.style);2123 tooltip.innerHTML = msg;2124 x = x - window.scrollX + added_box.tooltip.distanceX;2125 y = y - window.scrollY + added_box.tooltip.distanceY;2126 tooltip.style.left = x + "px";2127 tooltip.style.top = y + "px";2128 document.body.appendChild(tooltip);2129}21302131function CloseTooltip() {2132 var tooltip = document.getElementById(added_box.tooltip.id);2133 if(tooltip) {2134 tooltip.parentNode.removeChild(tooltip);2135 }2136}21372138function AddMetaData(pid) {2139 if(queue[pid].stat != STORED_DATA) return;21402141 Toggle_Listener(false);21422143 if(queue[pid]['originalHash']) {2144 AddCheckBox(pid);21452146 var download = document.getElementById(added_box.download.id+pid);2147 if(download && download.textContent.indexOf('(') < 0) {2148 download.innerHTML = custom.list.download_link_text + '('+queue[pid]['origExtension'].substr(1)+')<br />';2149 }2150 }21512152 var height = queue[pid].offsetHeight;21532154// Add user name(publisher name)2155 var id = added_box.meta.name_id + pid;2156 var name = document.getElementById(id);2157 if(!name) {2158 name = document.createElement('a');2159 name.id = id;2160 var href = 'http://www.veoh.com/users/'+queue[pid]['username'];2161 name.innerHTML = queue[pid]['username']+'<br />';2162 name.href = href;2163 queue[pid].node.appendChild(name);2164 }2165 var style = buildStyle(custom.style.list.name, added_box.meta.name_style);2166 if(custom.list.username && need_username == true) {2167 name.setAttribute('style',style + styles.block_open);2168 } else {2169 name.setAttribute('style',style + styles.close);2170 }21712172 var info = '';2173 if(custom.list.filesize) {2174 info += SizeToString(queue[pid]['size']) +"<br />";2175 }2176 if(custom.list.dateAdded) {2177 info += queue[pid]['dateAdded'] +"<br />";2178 }2179 if(custom.list.views) {2180 info += "Views("+queue[pid]['views'] +")<br />";2181 }2182 if(custom.list.downloads) {2183 info += "Downloads("+queue[pid]['numDownloads'] +")<br />";2184 }2185 if(custom.list.numofcomments) {2186 info += "Comments("+queue[pid]['numOfComments'] +")<br />";2187 }2188 if(custom.list.rating) {2189 info += "Rating("+queue[pid]['rating'];2190 info += "/"+queue[pid]['numRatingVotes'] +")<br />";2191 }21922193 id = added_box.meta.id + pid;2194 var div = document.getElementById(id);2195 if(!div) {2196 div = document.createElement('div');2197 div.id = id;2198 queue[pid].node.appendChild(div);2199 }2200 div.innerHTML = info;22012202 style = buildStyle(custom.style.list.meta, added_box.meta.style);2203 if(custom.list.filesize || custom.list.dateAdded || custom.list.numofcomments || custom.list.views || custom.list.downloads || custom.list.rating) {2204 div.setAttribute('style',style + styles.block_open);2205 } else {2206 div.setAttribute('style',style + styles.close);2207 }22082209// Add preview button2210 id = added_box.preview.id + pid;2211 var preview_button = document.getElementById(id);2212 if(!preview_button) {2213 preview_button = document.createElement('input');2214 preview_button.type = 'button';2215 preview_button.id = id;2216 preview_button.setAttribute("pid", pid);2217 preview_button.addEventListener("click",function(e) {2218 if(e.shiftKey) {2219 var pid = document.getElementById(this.id).getAttribute('pid');2220 DownloadPreviewVideo(pid);2221 } else {2222 PreviewVideo(this.id);2223 }2224 },false);2225 if(queue[pid]['previewUrl']) {2226 preview_button.addEventListener("mouseover",function(e) {2227 OpenTooltip(e.pageX, e.pageY, "Shift + Click : Download preview file");2228 },false);2229 preview_button.addEventListener("mouseout",function(e) {2230 CloseTooltip();2231 },false);2232 }22332234 queue[pid].node.appendChild(preview_button);2235 }2236 preview_button.value = custom.list.preview_button_text;2237 if(queue[pid]['previewExtension']) {2238 preview_button.value += '('+queue[pid]['previewExtension'].substr(1)+')';2239 }2240 style = buildStyle(custom.style.list.preview_button, added_box.preview.style);2241 if(custom.list.preview_button) {2242 preview_button.setAttribute('style',style + styles.block_open);2243 } else {2244 preview_button.setAttribute('style',style + styles.close);2245 }22462247 id = added_box.preview_download.id+pid;2248 var preview_download = document.getElementById(id);2249 if(!preview_download) {2250 preview_download = document.createElement('a');2251 preview_download.id = id;2252 preview_download.setAttribute("pid", pid);2253 preview_download.href = queue[pid]['previewUrl'];2254 preview_download.setAttribute('filename',ModifyFileName(queue[pid]['title'])+queue[pid]['previewExtension']);2255 preview_download.addEventListener("click",function(e) {2256 e.preventDefault();2257 var pid = document.getElementById(this.id).getAttribute('pid');2258 DownloadPreviewVideo(pid);2259 },false);2260 queue[pid].node.appendChild(preview_download);2261 }2262 preview_download.innerHTML = custom.list.download_preview_text+'('+queue[pid]['previewExtension'].substr(1)+')';2263 style = buildStyle(custom.style.list.preview_download, added_box.preview_download.style);2264 if(custom.list.download_preview && queue[pid]['previewUrl']) {2265 preview_download.setAttribute('style',style + styles.block_open);2266 } else {2267 preview_download.setAttribute('style',style + styles.close);2268 }226922702271 height += queue[pid].node.offsetHeight;2272 if(queue[pid].node.parentNode && queue[pid].node.parentNode.parentNode) {2273 queue[pid].node.parentNode.parentNode.setAttribute('style', 'height:'+height+'px');2274 }22752276 ModifyParentHeight(pid);2277 Toggle_Listener(true);2278}22792280// Drag&Drop and Resize for Video Panel2281var _startX = 0;2282var _startY = 0;2283var _offsetLeft = 0;2284var _offsetTop = 0;2285var _dragObj = null;2286var _dragObjStack = new Array();2287var _dragDisabled = false;2288var _resizeObj = null;2289var _resizeBox = null;2290var _playerNode = null;2291var _playerWidth = 0;2292var _playerHeight = 0;2293var _padding = new Array(4);22942295function setDragObject(obj) {2296 if(obj) {2297 _dragObjStack.push(_dragObj);2298 _dragObj = obj;2299 _dragObj.addEventListener('mousedown', dragStart, false);2300 } else {2301 document.removeEventListener("mousedown", dragStart, false);2302 _dragObj = _dragObjStack.pop();2303 }2304}23052306function dragStart(e) {2307 if(_dragDisabled == true) return;2308 if(!e.rangeParent) return;2309 if(e.rangeParent.nodeType == 1 && e.rangeParent.tagName == 'INPUT') return;23102311 _startX = e.clientX;2312 _startY = e.clientY;2313 _offsetLeft = _dragObj.offsetLeft;2314 _offsetTop = _dragObj.offsetTop;2315 document.addEventListener("mousemove", dragGo, true);2316 document.addEventListener("mouseup", dragStop, true);2317 e.preventDefault();2318}23192320function dragGo(e) {2321 e.preventDefault();2322 _dragObj.style.left = (_offsetLeft + e.clientX - _startX) + "px";2323 _dragObj.style.top = (_offsetTop + e.clientY - _startY) + "px";2324}23252326function dragStop(e) {2327 document.removeEventListener("mousemove", dragGo, true);2328 document.removeEventListener("mouseup", dragStop, true);2329}23302331function setResizeObject(obj, box) {2332 _resizeObj = obj;2333 _resizeBox = box;2334 _padding[0] = parseInt(obj.style.paddingTop);2335 _padding[1] = parseInt(obj.style.paddingRight);2336 _padding[2] = parseInt(obj.style.paddingBottom);2337 _padding[3] = parseInt(obj.style.paddingLeft);2338 if(_resizeObj && _resizeBox) {2339 _resizeBox.addEventListener('mousedown', resizeStart, false);2340 } else {2341 document.removeEventListener("mousedown", resizeStart, false);2342 }2343}23442345function resizeStart(e) {2346 _dragDisabled = true;2347 _startX = e.clientX;2348 _startY = e.clientY;2349 _offsetWidth = _resizeObj.offsetWidth;2350 _offsetHeight = _resizeObj.offsetHeight;2351 _playerNode = document.getElementById(video_panel.player.id);2352 _playerWidth = parseInt(_playerNode.width);2353 _playerHeight = parseInt(_playerNode.height);2354 document.addEventListener("mousemove", resizeGo, false);2355 document.addEventListener("mouseup", resizeStop, false);2356 e.preventDefault();2357}23582359function resizeGo(e) {2360 e.preventDefault();2361 var dist_width = e.clientX - _startX;2362 var dist_height = e.clientY - _startY;2363 if(_playerWidth + dist_width > custom.player.max_width) {2364 dist_width = custom.player.max_width - _playerWidth;2365 }2366 if(_playerWidth + dist_width < custom.player.min_width) {2367 dist_width = custom.player.min_width - _playerWidth;2368 }2369 if(aspect_ratio_locked) {2370 dist_height = (_playerWidth + dist_width) / aspect_ratio - _playerHeight;2371 }2372 if(_playerHeight + dist_height > custom.player.max_height) {2373 dist_height = custom.player.max_height - _playerHeight;2374 if(aspect_ratio_locked) {2375 dist_width = (_playerheight + dist_height) * aspect_ratio - _playerWidth;2376 }2377 }2378 if(_playerHeight + dist_height < custom.player.min_height) {2379 dist_height = custom.player.min_height - _playerHeight;2380 if(aspect_ratio_locked) {2381 dist_width = (_playerheight + dist_height) * aspect_ratio - _playerWidth;2382 }2383 }23842385 _playerNode.width = _playerWidth + dist_width;2386 _playerNode.height = _playerHeight + dist_height;2387 _resizeObj.style.width = (_offsetWidth + dist_width - _padding[1] - _padding[3]) + "px";2388 _resizeObj.style.height = (_offsetHeight + dist_height - _padding[0] - _padding[2]) + "px";23892390 MakeStatus(_playerNode);2391}23922393function resizeStop(e) {2394 document.removeEventListener("mousemove", resizeGo, false);2395 document.removeEventListener("mouseup", resizeStop, false);2396 last_width = _resizeObj.offsetWidth - _padding[1] - _padding[3];2397 last_height = _resizeObj.offsetHeight - _padding[0] - _padding[2];2398 last_player_width = parseInt(_playerNode.width);2399 last_player_height = parseInt(_playerNode.height);2400 _dragDisabled = false;24012402 MakeStatus(_playerNode);2403}240424052406function GetWatchBoxPosition() {2407 last_top = _resizeObj.offsetTop;2408 last_left = _resizeObj.offsetLeft;2409}24102411function setEmbedSize(div) {2412 var embed = document.getElementById(video_panel.player.id);2413 var pid = embed.getAttribute('pid');24142415 var height = 0;2416 var width = 0;2417 var top, left;2418 var auto_resize = custom.player.auto_resize;2419 var player_height = parseInt(custom.player.player_height);2420 var player_width = parseInt(custom.player.player_width);2421 var ratio = parseInt(queue[pid].video_width) / parseInt(queue[pid].video_height);24222423 if(auto_resize == true &&2424 queue[pid].video_width && queue[pid].video_height) {2425 embed.height = queue[pid].video_height;2426 embed.width = queue[pid].video_width;2427 if(embed.width > custom.player.max_width) {2428 embed.width = custom.player.max_width;2429 }2430 if(embed.height > custom.player.max_height) {2431 embed.height = custom.player.max_height;2432 }2433 height += embed.offsetTop;2434 height += parseInt(embed.height);2435 width += parseInt(embed.width);2436 } else {2437 if(player_width) {2438 embed.width = player_width;2439 width += parseInt(embed.width);2440 }2441 if(player_height) {2442 if(custom.player.fit_aspect_ratio && ratio) {2443 embed.height = embed.width / ratio;2444 } else {2445 embed.height = player_height;2446 }2447 height += parseInt(embed.height);2448 height += parseInt(embed.offsetTop);2449 }2450 }2451 aspect_ratio = embed.width / embed.height;24522453 if(!player_locked) {2454 var padding_height = parseInt(div.style.paddingTop)+parseInt(div.style.paddingBottom);2455 var padding_width = parseInt(div.style.paddingLeft)+parseInt(div.style.paddingRight);2456 top = custom.player.top;2457 left = custom.player.left;2458 if(top == 'center') {2459 top = (window.innerHeight - height - padding_height) / 2;2460 if(top < 0) {2461 top = 0;2462 }2463 }2464 if(left == 'center') {2465 left = (window.innerWidth - width - padding_width) / 2;2466 if(left < 0) {2467 left = 0;2468 }2469 }2470 div.style.cursor = 'move';2471 } else {2472 top = last_top;2473 left = last_left;2474 width = last_width;2475 height = last_height;2476 embed.width = last_player_width;2477 embed.height = last_player_height;2478 div.style.cursor = 'auto';2479 }2480 div.style.height = height + 'px';2481 div.style.width = width + 'px';2482 div.style.top = top + 'px';2483 div.style.left = left + 'px';24842485 MakeStatus(embed);24862487}24882489function PreviewVideo(id) {24902491 var pid = document.getElementById(id).getAttribute('pid');2492 var id = video_panel.box.id;2493 var div = document.getElementById(id);2494 var append = false;2495 var top;2496 var left;24972498 if(!div) {2499 div = document.createElement('div');2500 div.id = id;2501 append = true;2502 }2503 var embedCode = queue[pid]['embedCode']2504 if(custom.player.autoplay) {2505 embedCode = embedCode.replace('&player','&playAuto=1&player');2506 }25072508 div.innerHTML = embedCode;2509 div.firstChild.setAttribute('pid',pid);2510 div.firstChild.setAttribute('id',video_panel.player.id);2511 div.firstChild.setAttribute('style',video_panel.player.style);2512 var style = buildStyle(custom.style.video_panel.base, video_panel.box.style);2513 div.setAttribute('style', style);25142515 if(append == true) {2516 document.body.appendChild(div);2517 }25182519 append = false;2520 id = video_panel.title.id;2521 var title = document.getElementById(id);2522 if(!title) {2523 title = document.createElement('div');2524 title.id = id;2525 append = true;2526 }2527 title.innerHTML = queue[pid]['title'];2528 style = buildStyle(custom.style.video_panel.title, video_panel.title.style);2529 title.setAttribute('style', style);2530 if(append == true) {2531 div.insertBefore(title, div.firstChild);2532 }25332534 if(queue[pid]['previewUrl']) {2535 append = false;2536 id = video_panel.preview_download.id;2537 var download_button = document.getElementById(id);2538 if(!download_button) {2539 if(video_panel.preview_download.type == 'button') {2540 download_button = document.createElement('input');2541 download_button.type = 'button';2542 } else {2543 download_button = document.createElement('a');2544 }2545 download_button.id = id;2546 append = true;2547 }254825492550 var text = custom.player.download_link_text+'('+queue[pid]['previewExtension'].substr(1)+')'2551 if(video_panel.preview_download.type == 'button') {2552 download_button.value = text;2553 } else {2554 download_button.href = queue[pid]['previewUrl'];2555 download_button.innerHTML = text;2556 }2557 download_button.setAttribute('title',queue[pid]['title']);2558 download_button.setAttribute('filename',ModifyFileName(queue[pid]['title'])+queue[pid]['previewExtension']);2559 style = buildStyle(custom.style.video_panel.download, video_panel.preview_download.style);2560 download_button.setAttribute('style', style);2561 if(custom.player.download_preview) {2562 download_button.style.display = 'block';2563 } else {2564 download_button.style.display = 'none';2565 }2566 if(append == true) {2567 div.appendChild(download_button);2568 download_button.addEventListener("click",function(e) {2569 e.preventDefault();2570 DownloadPreviewVideo(pid);2571 },false);2572 }2573 }25742575 aspect_ratio_locked = custom.player.lock_ratio;25762577 id = video_panel.close.id;2578 var close_button = document.getElementById(id);2579 if(!close_button) {2580 close_button = document.createElement('input');2581 close_button.type = 'button';2582 close_button.value = 'X';2583 close_button.id = id;2584 style = buildStyle(custom.style.video_panel.close, video_panel.close.style);2585 close_button.setAttribute('style', style);2586// div.appendChild(close_button);2587 title.appendChild(close_button);2588 close_button.addEventListener("click",ClosePreviewVideo,false);2589 }25902591 id = video_panel.status_bar.id;2592 var status_bar = document.getElementById(id);2593 if(!status_bar) {2594 status_bar = document.createElement('div');2595 status_bar.innerHTML = '';2596 status_bar.id = id;2597 style = buildStyle(custom.style.video_panel.status_bar, video_panel.status_bar.style);2598 status_bar.setAttribute('style', style);2599 div.appendChild(status_bar);2600 }26012602 id = video_panel.resize.id;2603 var resize_box = document.getElementById(id);2604 if(!resize_box) {2605 resize_box = document.createElement('div');2606 resize_box.innerHTML = '';2607 resize_box.id = id;2608 resize_box.setAttribute('style', video_panel.resize.style);2609 resize_box.style.cursor = 'se-resize';2610 div.appendChild(resize_box);2611 }26122613 setEmbedSize(div);26142615 setResizeObject(div, resize_box);26162617 id = video_panel.lock.id;2618 var lock_button = document.getElementById(id);2619 if(!lock_button) {2620 lock_button = document.createElement('input');2621 lock_button.type = 'button';2622 if(!player_locked) {2623 lock_button.value = 'Lock';2624 } else {2625 lock_button.value = 'Unlock';2626 }2627 lock_button.id = id;2628 style = buildStyle(custom.style.video_panel.lock, video_panel.lock.style);2629 lock_button.setAttribute('style', style);2630// div.appendChild(lock_button);2631 title.appendChild(lock_button);2632 lock_button.addEventListener("click",function(e) {2633 var div = document.getElementById(video_panel.box.id);2634 var btn = document.getElementById(video_panel.lock.id);2635 if(!player_locked) {2636 player_locked = true;2637 setDragObject(null);2638 btn.value = 'Unlock';2639 GetWatchBoxPosition();2640 div.style.cursor = 'auto';2641 } else {2642 player_locked = false;2643 setDragObject(div);2644 btn.value = 'Lock';2645 div.style.cursor = 'move';2646 }2647 },false);2648 }26492650 if(!player_locked) {2651 setDragObject(div);2652 }26532654 if(document.getElementById(setup_box.base.id)) {2655 Player_Visible(false);2656 window.alert("The video panel is hidden. Close the setup panel to show it.");2657 }2658}26592660function MakeStatus(embed) {2661 var pid = embed.getAttribute('pid');2662 var status = "Resolution: "+queue[pid].video_width+"x"+queue[pid].video_height;2663 var ratio = Math.round(queue[pid].video_width/queue[pid].video_height * 1000)/1000;2664 status += " Ratio: "+ratio;2665 status += " Player size: "+embed.width+"x"+embed.height;2666 ratio = Math.round(embed.width/embed.height*1000)/1000;2667 status += " Ratio: "+ratio;2668 WriteStatusBar(status);2669}26702671function WriteStatusBar(status) {2672 var status_bar = document.getElementById(video_panel.status_bar.id);2673 if(!status_bar) return;2674 status_bar.innerHTML = status;2675}26762677function DownloadPreviewVideo(pid) {2678 if(queue[pid]['previewUrl']) {2679 window.location.href = queue[pid]['previewUrl'];2680 }2681}26822683function ClosePreviewVideo() {2684 var id = video_panel.box.id;2685 var div = document.getElementById(id);2686 if(div) {2687 div.setAttribute('style', video_panel.box.close_style);2688 }2689 setDragObject(null);2690}26912692function ModifyParentHeight(pid) {2693 var work = new Array();2694 var height = 0;2695 var base_height = 0;2696 for (var wpid in queue) {2697 if(queue[wpid].offsetTop == queue[pid].offsetTop) {2698 if(!queue[wpid].node) continue;2699 if(!queue[wpid].node.parentNode) continue;2700 work.push(wpid);2701// if(queue[wpid].stat != STORED_DATA) {2702// continue;2703// }2704 if(queue[wpid].node.offsetHeight > base_height) {2705 base_height = queue[wpid].node.offsetHeight;2706 }2707 if(queue[wpid].offsetHeight + queue[wpid].node.offsetHeight > height) {2708 height = queue[wpid].offsetHeight + queue[wpid].node.offsetHeight;2709 }2710 }2711 }2712 if(height) {2713 for (var wpid in work) {2714 if(!queue[work[wpid]].node) continue;2715 if(queue[work[wpid]].cell_calc_type == TYPE_HEIGHT_CALC) {2716 queue[work[wpid]].node.parentNode.style.height = (queue[work[wpid]].offsetHeight + base_height)+'px';2717 queue[work[wpid]].video_cell.style.height = (queue[work[wpid]].cell_offsetHeight + base_height)+'px';2718 } else {2719 queue[work[wpid]].node.parentNode.style.height = 'auto';2720 queue[work[wpid]].video_cell.style.height = 'auto';2721 }2722 }2723 }2724}27252726function Update_List_Page() {2727 SetNeedInformation();2728 for (var pid in queue) {2729 AddCheckBox(pid);2730 if(queue[pid].stat == STORED_DATA) {2731 AddMetaData(pid);2732 }2733 }2734 var div = document.getElementById(video_panel.box.id);2735 if(div) {2736 setEmbedSize(div);2737 }2738 ChangeButtonBoxMode(added_buttons.top.id, custom.list.check_box_option)2739 ChangeButtonBoxMode(added_buttons.bottom.id, custom.list.check_box_option)2740}27412742function Update_Watch_Page() {2743 ChangeStyle();27442745 if(custom.watch.detail_information == true) {2746 Change_Information_Box(styles.block_open);2747 } else {2748 Change_Information_Box(styles.close);2749 }2750 addMetaInfo();2751}27522753function Update_Video_Panel() {2754 var download_button = document.getElementById(video_panel.preview_download.id);2755 if(!download_button) {2756 return;2757 }2758 var filename = download_button.getAttribute('filename');2759 if(!filename) return;2760 var ext = filename.match(/.*\.(.+)/)[1];2761 var text = custom.player.download_preview_text+'('+ext+')';2762 if(video_panel.preview_download.type == 'button') {2763 download_button.value = text;2764 } else {2765 download_button.innerHTML = text;2766 }2767 style = buildStyle(custom.style.video_panel.download, video_panel.preview_download.style);2768 download_button.setAttribute('style', style);2769 if(custom.player.download_preview) {2770 download_button.style.display = 'block';2771 } else {2772 download_button.style.display = 'none';2773 }2774}27752776// Change style for download link2777function ChangeStyle() {27782779 SetButtonStyle(added_box_watch.original, custom.watch.download_link_text);2780 SetButtonStyle(added_box_watch.preview, custom.watch.download_preview_text);2781 SetButtonStyle(added_box_watch.mp4, custom.watch.iPhone_text);27822783 base_node = document.getElementById(added_box_watch.original.div_id);2784 if(custom.watch.download_original) {2785 base_node.style.display = "block";2786 } else {2787 base_node.style.display = "none";2788 }2789 base_node = document.getElementById(added_box_watch.preview.div_id);2790 if(custom.watch.download_preview) {2791 base_node.style.display = "block";2792 } else {2793 base_node.style.display = "none";2794 }2795 base_node = document.getElementById(added_box_watch.mp4.div_id);2796 if(custom.watch.iPhone) {2797 base_node.style.display = "block";2798 } else {2799 base_node.style.display = "none";2800 }2801}28022803// Set button style2804function SetButtonStyle(box, link_text) {2805 var base_node = document.getElementById(box.div_id);2806 var anchorlink = document.getElementById(box.anchor_id);2807 var style = buildStyle(custom.style.watch.download,box.div_style);2808 var anchor_style = buildStyle(custom.style.watch.anchor,box.anchor_style);28092810 base_node.setAttribute('style',style);2811 anchorlink.innerHTML = link_text;2812 anchorlink.setAttribute('style',anchor_style);2813}28142815function Change_Information_Box(box_style) {2816 var div = document.getElementById(added_box_watch.info.box_id);2817 div.setAttribute('style', box_style);2818 var node = document.getElementById(added_box_watch.info.btn_id);2819 if(box_style == styles.block_open) {2820 openVideoInformation = true;2821 node.setAttribute('value', 'Close Video Information');2822 } else {2823 openVideoInformation = false;2824 node.setAttribute('value', 'Open Video Information');2825 }2826}282728282829function Center_Position(div) {2830 var height = div.offsetHeight;2831 var width = div.offsetWidth;2832 var top = 0;2833 var left = 0;2834 top = (window.innerHeight - height) / 2;2835 if(top < 0) {2836 top = 0;2837 }2838 left = (window.innerWidth - width) / 2;2839 if(left < 0) {2840 left = 0;2841 }2842 div.style.top = top + 'px';2843 div.style.left = left + 'px';2844}28452846function Setup() {2847 if(document.getElementById(setup_box.base.id)) return;28482849 var list_html = Make_Html_For_List_Page();2850 var video_html = Make_Html_For_Video_Panel();2851 var watch_html = Make_Html_For_Watch_Page();2852 var script_html = Make_Html_For_Script_Control();2853 var update_html = Make_Html_For_Update_Checker();28542855 var html = ''+2856 '<div style="'+setup_box.base.title_style+'">Set up</div>' +2857 '<hr style="'+setup_box.base.hr_style+'" />'+2858 '<div style="'+setup_box.base.tabs_style+'">' +2859 '<ul style="'+setup_box.base.ul_style+'">' +2860 '<li id="'+setup_box.tabs.list.id+'" style="'+setup_box.tabs.list.style_active+'">List<br />page</li>' +2861 '<li id="'+setup_box.tabs.video.id+'" style="'+setup_box.tabs.video.style+'">Video<br />panel</li>' +2862 '<li id="'+setup_box.tabs.watch.id+'" style="'+setup_box.tabs.watch.style+'">Watch<br />page</li>' +2863 '<li id="'+setup_box.tabs.script.id+'" style="'+setup_box.tabs.script.style+'">Script<br />control</li>' +2864 '<li id="'+setup_box.tabs.update.id+'" style="'+setup_box.tabs.update.style+'">Update<br />checker</li>' +2865 '</ul>'+2866 '</div>'+2867 '<div id="'+setup_box.tabs.list.box_id+'" style="'+setup_box.base.box_style_active+'">' +2868 list_html +2869 '</div>'+2870 '<div id="'+setup_box.tabs.video.box_id+'" style="'+setup_box.base.box_style+'">' +2871 video_html +2872 '</div>'+2873 '<div id="'+setup_box.tabs.watch.box_id+'" style="'+setup_box.base.box_style+'">' +2874 watch_html +2875 '</div>'+2876 '<div id="'+setup_box.tabs.script.box_id+'" style="'+setup_box.base.box_style+'">' +2877 script_html +2878 '</div>'+2879 '<div id="'+setup_box.tabs.update.box_id+'" style="'+setup_box.base.box_style+'">' +2880 update_html +2881 '</div>'+2882 '</div>'+2883 '';28842885 var base = document.createElement('div');2886 base.innerHTML = html;2887 base.id = setup_box.base.id;2888 base.setAttribute('style', setup_box.base.style);28892890 var ok = document.createElement('input');2891 ok.type = 'button';2892 ok.id = setup_box.button.ok_id;2893 ok.setAttribute('style',setup_box.button.ok_style);2894 ok.value = 'OK';28952896 var cancel = document.createElement('input');2897 cancel.type = 'button';2898 cancel.id = setup_box.button.cancel_id;2899 cancel.setAttribute('style',setup_box.button.cancel_style);2900 cancel.value = 'Cancel';29012902 var check_now = document.createElement('input');2903 check_now.type = 'button';2904 check_now.id = setup_box.update.check_now_id;2905 check_now.setAttribute('style',setup_box.update.check_now_style);2906 check_now.value = 'Check now';29072908 ok.addEventListener("click",Save_Setup_Information,false);2909 cancel.addEventListener("click",Close_Box,false);2910 check_now.addEventListener("click",Update_Check_Force,false);29112912 base.appendChild(ok);2913 base.appendChild(cancel);29142915 document.body.appendChild(base);29162917 var update_box = document.getElementById(setup_box.tabs.update.box_id);2918 update_box.appendChild(check_now);29192920 var list_tab = document.getElementById(setup_box.tabs.list.id);2921 var video_tab = document.getElementById(setup_box.tabs.video.id);2922 var watch_tab = document.getElementById(setup_box.tabs.watch.id);2923 var script_tab = document.getElementById(setup_box.tabs.script.id);2924 var update_tab = document.getElementById(setup_box.tabs.update.id);29252926 list_tab.setAttribute('stat', 'on');2927 video_tab.setAttribute('stat', 'off');2928 watch_tab.setAttribute('stat', 'off');2929 script_tab.setAttribute('stat', 'off');2930 update_tab.setAttribute('stat', 'off');29312932 list_tab.addEventListener("click", function(e) {TabClicked(this.id);}, false);2933 video_tab.addEventListener("click", function(e) {TabClicked(this.id);}, false);2934 watch_tab.addEventListener("click", function(e) {TabClicked(this.id);}, false);2935 script_tab.addEventListener("click", function(e) {TabClicked(this.id);}, false);2936 update_tab.addEventListener("click", function(e) {TabClicked(this.id);}, false);293729382939 Setup_List_Page();2940 Setup_Video_Panel();2941 Setup_Watch_Page();2942 Setup_Script_Control();2943 Setup_Update_Check();29442945 Center_Position(base);29462947 Player_Visible(false);29482949 base.style.cursor = 'move';2950 setDragObject(base);2951}29522953function TabClicked(id) {2954 var node = document.getElementById(id);2955 if(node.getAttribute('stat') == 'on') {2956 return;2957 }2958 var on_tab;2959 var clicked_tab;2960 for (var i in setup_box.tabs) {2961 var tab = document.getElementById(setup_box.tabs[i].id);2962 if(tab.getAttribute('stat') == 'on') {2963 on_tab = setup_box.tabs[i];2964 }2965 if(id == setup_box.tabs[i].id) {2966 clicked_tab = setup_box.tabs[i];2967 }2968 }2969 ToggleTab(clicked_tab);2970 ToggleTab(on_tab);2971}29722973function ToggleTab(param) {2974 var node = document.getElementById(param.id);2975 var box_node = document.getElementById(param.box_id);2976 if(node.getAttribute('stat') == 'on') {2977 node.setAttribute('stat','off');2978 node.setAttribute('style',param.style);2979 box_node.style.display = 'none';2980 } else {2981 node.setAttribute('stat','on');2982 node.setAttribute('style',param.style_active);2983 box_node.style.display = 'block';2984 }2985}298629872988function Save_Setup_Information() {2989 if(Check_Options_List_Page() == false) {2990 alert("The setting of List page is invalid");2991 return ;2992 }2993 if(Check_Options_Video_Panel() == false) {2994 alert("The setting of Video panel is invalid");2995 return ;2996 }2997 if(Check_Options_Watch_Page() == false) {2998 alert("The setting of Watch page is invalid");2999 return ;3000 }30013002 if(Check_Options_Script_Control() == false) {3003 alert("The setting of Script control is invalid");3004 return ;3005 }30063007 if(Check_Options_Update_Checker() == false) {3008 alert("The setting of Update checker is invalid");3009 return ;3010 }30113012 SetSetupDataVersion();3013 Save_Options_List_Page();3014 Save_Options_Video_Panel();3015 Save_Options_Watch_Page();3016 Save_Options_Script_Control();3017 Save_Options_Update_Checker();3018 Save_Options_Others();30193020 Close_Box();30213022 if(watch_page == true) {3023 Update_Watch_Page();3024 }3025 Update_List_Page();3026 Update_Video_Panel();30273028}30293030function Setup_Set_Check_Box(id, val, style) {3031 var node = document.getElementById(id);3032 if(style) {3033 node.setAttribute('style',setup_box.checkbox.style + style);3034 } else {3035 node.setAttribute('style',setup_box.checkbox.style);3036 }3037 node.checked = val;3038}30393040function Setup_Set_Text_Box(id, val) {3041 var node = document.getElementById(id);3042 node.setAttribute('style',setup_box.textbox.style);3043 node.value = val;3044}30453046function Setup_Set_Radio_Button(id, checked) {3047 var node = document.getElementById(id);3048 node.setAttribute('style',setup_box.radio.style);3049 if(checked) {3050 node.checked = true;3051 } else {3052 node.checked = false;3053 }3054}30553056function Make_Html_For_List_Page() {3057 var html = ''+3058 '<ul style="'+setup_box.list.ul_style+'"><b>About check box, link and button</b><br />' +3059 '<li style="'+setup_box.list.chkeckbox_style+'"><input type="checkbox" id="'+setup_box.list.checkbox_id+'">Check box and download link</li>' +3060 '<li style="'+setup_box.list.download_link_text_style+'">Text<input type="text" id="'+setup_box.list.download_link_text_id+'" value="'+custom.list.download_link_text+'"></li>'+3061 '<li style="'+setup_box.list.preview_button_style+'"><input type="checkbox" id="'+setup_box.list.preview_button_id+'">Preview button</li>' +3062 '<li style="'+setup_box.list.preview_button_text_style+'">Text<input type="text" id="'+setup_box.list.preview_button_text_id+'" value="'+custom.list.preview_button_text+'"></li>'+3063 '<li style="'+setup_box.list.download_preview_style+'"><input type="checkbox" id="'+setup_box.list.download_preview_id+'">Download preview link</li>' +3064 '<li style="'+setup_box.list.download_preview_text_style+'">Text<input type="text" id="'+setup_box.list.download_preview_text_id+'" value="'+custom.list.download_preview_text+'"></li>'+3065 '</ul>'+3066 '<br />'+3067 '<ul style="'+setup_box.list.ul_style+'"><b>About video informations</b><br />' +3068 '<li style="'+setup_box.list.publisher_style+'"><input type="checkbox" id="'+setup_box.list.publisher_id+'">Publisher name with link</li>' +3069 '<li style="'+setup_box.list.filesize_style+'"><input type="checkbox" id="'+setup_box.list.filesize_id+'">File size ' +3070 '<input type="checkbox" id="'+setup_box.list.filesize_byte_id+'">with byte size</li>' +3071 '<li style="'+setup_box.list.added_date_style+'"><input type="checkbox" id="'+setup_box.list.added_date_id+'">Added date</li>' +3072 '<li style="'+setup_box.list.views_style+'"><input type="checkbox" id="'+setup_box.list.views_id+'">Number of views</li>' +3073 '<li style="'+setup_box.list.downloads_style+'"><input type="checkbox" id="'+setup_box.list.downloads_id+'">Number of downloads</li>' +3074 '<li style="'+setup_box.list.comments_style+'"><input type="checkbox" id="'+setup_box.list.comments_id+'">Number of comments</li>' +3075 '<li style="'+setup_box.list.rating_style+'"><input type="checkbox" id="'+setup_box.list.rating_id+'">Rating and number of votes</li>' +3076 '</ul>'+3077 '';30783079 return html;3080}30813082function Setup_List_Page() {30833084 Setup_Set_Check_Box(setup_box.list.checkbox_id, custom.list.check_box_option);3085 Setup_Set_Text_Box(setup_box.list.download_link_text_id, custom.list.download_link_text);3086 Setup_Set_Check_Box(setup_box.list.preview_button_id, custom.list.preview_button);3087 Setup_Set_Text_Box(setup_box.list.preview_button_text_id, custom.list.preview_button_text);3088 Setup_Set_Check_Box(setup_box.list.download_preview_id, custom.list.download_preview);3089 Setup_Set_Text_Box(setup_box.list.download_preview_text_id, custom.list.download_preview_text);3090 Setup_Set_Check_Box(setup_box.list.publisher_id, custom.list.username);3091 Setup_Set_Check_Box(setup_box.list.filesize_id, custom.list.filesize);3092 Setup_Set_Check_Box(setup_box.list.filesize_byte_id, custom.list.filesize_byte);3093 Setup_Set_Check_Box(setup_box.list.added_date_id, custom.list.dateAdded);3094 Setup_Set_Check_Box(setup_box.list.views_id, custom.list.views);3095 Setup_Set_Check_Box(setup_box.list.downloads_id, custom.list.downloads);3096 Setup_Set_Check_Box(setup_box.list.comments_id, custom.list.numofcomments);3097 Setup_Set_Check_Box(setup_box.list.rating_id, custom.list.rating);30983099}31003101function Check_Options_List_Page() {3102 return true;3103}31043105function Save_Options_List_Page() {3106 custom.list.check_box_option = document.getElementById(setup_box.list.checkbox_id).checked;3107 custom.list.download_link_text = document.getElementById(setup_box.list.download_link_text_id).value;3108 custom.list.preview_button = document.getElementById(setup_box.list.preview_button_id).checked;3109 custom.list.preview_button_text = document.getElementById(setup_box.list.preview_button_text_id).value;3110 custom.list.download_preview = document.getElementById(setup_box.list.download_preview_id).checked;3111 custom.list.download_preview_text = document.getElementById(setup_box.list.download_preview_text_id).value;3112 custom.list.username = document.getElementById(setup_box.list.publisher_id).checked;3113 custom.list.filesize = document.getElementById(setup_box.list.filesize_id).checked;3114 custom.list.filesize_byte = document.getElementById(setup_box.list.filesize_byte_id).checked;3115 custom.list.dateAdded = document.getElementById(setup_box.list.added_date_id).checked;3116 custom.list.views = document.getElementById(setup_box.list.views_id).checked;3117 custom.list.downloads = document.getElementById(setup_box.list.downloads_id).checked;3118 custom.list.numofcomments = document.getElementById(setup_box.list.comments_id).checked;3119 custom.list.rating = document.getElementById(setup_box.list.rating_id).checked;31203121 SetSetupDataListPage();3122}31233124function Make_Html_For_Video_Panel() {3125 var html = ''+3126 '<ul style="'+setup_box.video.ul_style+'"><b>About player</b><br />' +3127 '<li style="'+setup_box.video.autoplay_style+'"><input type="checkbox" id="'+setup_box.video.autoplay_id+'">Autoplay</li>' +3128 '<li style="'+setup_box.video.auto_resize_style+'"><input type="checkbox" id="'+setup_box.video.auto_resize_id+'">Auto Resize</li>' +3129// '<li style="'+setup_box.video.lock_ratio_style+'"><input type="checkbox" id="'+setup_box.video.lock_ratio_id+'">Lock aspect ratio</li>'+3130 '<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' +3131 '</li>'+3132 '<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 ' +3133 '<input type="checkbox" id="'+setup_box.video.fit_aspect_ratio_id+'">Fit aspect ratio'+3134 '</li>'+3135 '<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+'"> - '+3136 '<input type="text" id="'+setup_box.video.max_width_id+'" size="4" value="'+custom.player.max_width+'"> px</li>'+3137 '<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+'"> - '+3138 '<input type="text" id="'+setup_box.video.max_height_id+'" size="4" value="'+custom.player.max_height+'"> px</li>'+3139 '</ul>'+3140 '<br />'+3141 '<ul style="'+setup_box.video.ul_style+'"><b>About items on the panel</b><br />' +3142 '<li style="'+setup_box.video.download_preview_style+'"><input type="checkbox" id="'+setup_box.video.download_preview_id+'">Download preview link</li>' +3143 '<li style="'+setup_box.video.download_preview_text_style+'">Text<input type="text" id="'+setup_box.video.download_preview_text_id+'" value="'+custom.player.download_preview_text+'" size="30"></li>'+3144 '</ul>'+3145 '';31463147 return html;3148}31493150function Setup_Video_Panel() {31513152 Setup_Set_Check_Box(setup_box.video.autoplay_id, custom.player.autoplay);3153 Setup_Set_Check_Box(setup_box.video.auto_resize_id, custom.player.auto_resize);3154// Setup_Set_Check_Box(setup_box.video.lock_ratio_id, custom.player.lock_ratio);3155 Setup_Set_Text_Box(setup_box.video.width_id, custom.player.player_width);3156 Setup_Set_Text_Box(setup_box.video.height_id, custom.player.player_height);3157 Setup_Set_Check_Box(setup_box.video.fit_aspect_ratio_id, custom.player.fit_aspect_ratio, setup_box.video.fit_aspect_ratio_style);3158 Setup_Set_Text_Box(setup_box.video.min_width_id, custom.player.min_width);3159 Setup_Set_Text_Box(setup_box.video.min_height_id, custom.player.min_height);3160 Setup_Set_Text_Box(setup_box.video.max_width_id, custom.player.max_width);3161 Setup_Set_Text_Box(setup_box.video.max_height_id, custom.player.max_height);3162 Setup_Set_Check_Box(setup_box.video.download_preview_id, custom.player.download_preview);3163 Setup_Set_Text_Box(setup_box.video.download_preview_text_id, custom.player.download_preview_text);31643165}31663167function Check_Options_Video_Panel() {3168 var player_width = parseInt(document.getElementById(setup_box.video.width_id).value);3169 var player_height = parseInt(document.getElementById(setup_box.video.height_id).value);3170 var min_width = parseInt(document.getElementById(setup_box.video.min_width_id).value);3171 var min_height = parseInt(document.getElementById(setup_box.video.min_height_id).value);3172 var max_width = parseInt(document.getElementById(setup_box.video.max_width_id).value);3173 var max_height = parseInt(document.getElementById(setup_box.video.max_height_id).value);3174 if(player_width < MIN_WIDTH) return false;3175 if(player_height < MIN_HEIGHT) return false;3176 if(player_width > MAX_WIDTH) return false;3177 if(player_height > MAX_HEIGHT) return false;3178 if(max_width < MIN_WIDTH) return false;3179 if(max_height < MIN_HEIGHT) return false;3180 if(max_width > MAX_WIDTH) return false;3181 if(max_height > MAX_HEIGHT) return false;3182 if(min_width < MIN_WIDTH) return false;3183 if(min_height < MIN_HEIGHT) return false;3184 if(min_width > MAX_WIDTH) return false;3185 if(min_height > MAX_HEIGHT) return false;3186 if(min_width > max_width) return false;3187 if(min_height > max_height) return false;3188 if(player_width < min_width) return false;3189 if(player_height < min_height) return false;3190 if(player_width > max_width) return false;3191 if(player_height > max_height) return false;3192 return true;3193}31943195function Save_Options_Video_Panel() {3196 custom.player.autoplay = document.getElementById(setup_box.video.autoplay_id).checked;3197 custom.player.auto_resize = document.getElementById(setup_box.video.auto_resize_id).checked;3198// custom.player.lock_ratio = document.getElementById(setup_box.video.lock_ratio_id).checked;3199 custom.player.player_width = parseInt(document.getElementById(setup_box.video.width_id).value);3200 custom.player.player_height = parseInt(document.getElementById(setup_box.video.height_id).value);3201 custom.player.fit_aspect_ratio = document.getElementById(setup_box.video.fit_aspect_ratio_id).checked;3202 custom.player.min_width = parseInt(document.getElementById(setup_box.video.min_width_id).value);3203 custom.player.min_height = parseInt(document.getElementById(setup_box.video.min_height_id).value);3204 custom.player.max_width = parseInt(document.getElementById(setup_box.video.max_width_id).value);3205 custom.player.max_height = parseInt(document.getElementById(setup_box.video.max_height_id).value);3206 custom.player.download_preview = document.getElementById(setup_box.video.download_preview_id).checked;3207 custom.player.download_preview_text = document.getElementById(setup_box.video.download_preview_text_id).value;32083209 SetSetupDataVideoPanel();3210}32113212function Make_Html_For_Watch_Page() {3213 var html = ''+3214 '<ul style="'+setup_box.watch.ul_style+'"><b>About buttons</b><br />' +3215 '<li style="'+setup_box.watch.download_original_style+'">'+3216 '<input type="checkbox" id="'+setup_box.watch.download_original_id+'">Download original video</li>' +3217 '<li style="'+setup_box.watch.download_link_text_style+'">Text<input type="text" id="'+setup_box.watch.download_link_text_id+'" value="'+custom.watch.download_link_text+'" size="30">' +3218 '</li>'+3219 '<li style="'+setup_box.watch.download_preview_style+'">'+3220 '<input type="checkbox" id="'+setup_box.watch.download_preview_id+'">Download preview video</li>' +3221 '<li style="'+setup_box.watch.download_preview_text_style+'">Text<input type="text" id="'+setup_box.watch.download_preview_text_id+'" value="'+custom.watch.download_preview_text+'" size="30">' +3222 '</li>'+3223 '<li style="'+setup_box.watch.iPhone_style+'">'+3224 '<input type="checkbox" id="'+setup_box.watch.iPhone_id+'">Go to iPhone page</li>' +3225 '<li style="'+setup_box.watch.iPhone_text_style+'">Text<input type="text" id="'+setup_box.watch.iPhone_text_id+'" value="'+custom.watch.iPhone_text+'" size="30">' +3226 '</li>'+3227// '</ul>' +3228// '<ul style="'+setup_box.watch.ul_style+'"><br />' +3229 '<li style="'+setup_box.watch.text_color_style+'">Text color <input type="text" id="'+setup_box.watch.text_color_id+'" value="'+custom.style.watch.anchor.text_color+'">' +3230 '</li>'+3231 '<li style="'+setup_box.watch.bg_color_style+'">Background color <input type="text" id="'+setup_box.watch.bg_color_id+'" value="'+custom.style.watch.anchor.bg_color+'">' +3232 '</li>'+3233 '<li style="'+setup_box.watch.bg_image_style+'">Background image <input type="text" id="'+setup_box.watch.bg_image_id+'" size="50" value="'+custom.style.watch.anchor.bg_image+'">' +3234 '</li>'+3235 '</ul>'+3236 '<br />'+3237 '<ul style="'+setup_box.watch.ul_style+'"><b>About video informations</b><br />' +3238 '<li style="'+setup_box.watch.information_style+'">'+3239 '<input type="checkbox" id="'+setup_box.watch.information_id+'">Shows video informations box</li>' +3240 '<li style="'+setup_box.watch.meta_data_style+'">'+3241 '<input type="checkbox" id="'+setup_box.watch.meta_data_id+'">Adds meta data</li>' +3242 '<li style="'+setup_box.watch.convert_utf8_style+'">'+3243 '<input type="checkbox" id="'+setup_box.watch.convert_utf8_id+'">Converts text to UTF8</li>' +3244 '</ul>'+3245 '';32463247 return html;3248}324932503251function Setup_Watch_Page() {32523253 Setup_Set_Text_Box(setup_box.watch.text_color_id, custom.style.watch.anchor.text_color);3254 Setup_Set_Text_Box(setup_box.watch.bg_color_id, custom.style.watch.anchor.bg_color);3255 Setup_Set_Text_Box(setup_box.watch.bg_image_id, custom.style.watch.anchor.bg_image);3256 Setup_Set_Check_Box(setup_box.watch.download_original_id, custom.watch.download_original);3257 Setup_Set_Text_Box(setup_box.watch.download_link_text_id, custom.watch.download_link_text);3258 Setup_Set_Check_Box(setup_box.watch.download_preview_id, custom.watch.download_preview);3259 Setup_Set_Text_Box(setup_box.watch.download_preview_text_id, custom.watch.download_preview_text);3260 Setup_Set_Check_Box(setup_box.watch.iPhone_id, custom.watch.iPhone);3261 Setup_Set_Text_Box(setup_box.watch.iPhone_text_id, custom.watch.iPhone_text);3262 Setup_Set_Check_Box(setup_box.watch.information_id, custom.watch.detail_information);3263 Setup_Set_Check_Box(setup_box.watch.meta_data_id, custom.watch.meta_data_option);3264 Setup_Set_Check_Box(setup_box.watch.convert_utf8_id, custom.watch.convert_utf8);32653266}32673268function Check_Options_Watch_Page() {3269 return true;3270}32713272function Save_Options_Watch_Page() {3273 custom.style.watch.anchor.text_color = document.getElementById(setup_box.watch.text_color_id).value;3274 custom.style.watch.anchor.bg_color = document.getElementById(setup_box.watch.bg_color_id).value;3275 custom.style.watch.anchor.bg_image = document.getElementById(setup_box.watch.bg_image_id).value;3276 custom.watch.download_original = document.getElementById(setup_box.watch.download_original_id).checked;3277 custom.watch.download_link_text = document.getElementById(setup_box.watch.download_link_text_id).value;3278 custom.watch.download_preview = document.getElementById(setup_box.watch.download_preview_id).checked;3279 custom.watch.download_preview_text = document.getElementById(setup_box.watch.download_preview_text_id).value;3280 custom.watch.iPhone = document.getElementById(setup_box.watch.iPhone_id).checked;3281 custom.watch.iPhone_text = document.getElementById(setup_box.watch.iPhone_text_id).value;3282 custom.watch.detail_information = document.getElementById(setup_box.watch.information_id).checked;3283 custom.watch.meta_data_option = document.getElementById(setup_box.watch.meta_data_id).checked;3284 custom.watch.convert_utf8 = document.getElementById(setup_box.watch.convert_utf8_id).checked;32853286 SetSetupDataWatchPage();3287}32883289// for script control tab3290function Make_Html_For_Script_Control() {3291 var html = ''+3292 '<ul style="'+setup_box.script.ul_style+'"><b>About queue control</b><br />' +3293 '<li style="'+setup_box.script.check_interval_style+'">Check interval<input type="text" id="'+setup_box.script.check_interval_id+'" size="2">sec' +3294 ' (' + MIN_INTERVAL + '-' + MAX_INTERVAL +')</li>' +3295 '<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' +3296 ' (' + MIN_INTERVAL + '-' + MAX_INTERVAL +')</li>' +3297 '<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">' +3298 ' (' + MIN_MAX_SEND + '-' + MAX_MAX_SEND +')</li>' +3299 '<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' +3300 ' (' + MIN_MAX_WAIT + '-' + MAX_MAX_WAIT +')</li>' +3301 '<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' +3302 ' (' + MIN_MAX_RETRY + '-' + MAX_MAX_RETRY +')</li>' +3303 '</ul>'+3304 '';3305 return html;3306}33073308function Setup_Script_Control() {33093310 Setup_Set_Text_Box(setup_box.script.check_interval_id, parseInt(custom.queue.check_interval / 1000));3311 Setup_Set_Text_Box(setup_box.script.check_interval_done_id, parseInt(custom.queue.check_interval_done / 1000));3312 Setup_Set_Text_Box(setup_box.script.max_send_request_id, custom.queue.max_send_request);3313 Setup_Set_Text_Box(setup_box.script.max_wait_limit_id, parseInt(custom.queue.max_wait_limit / 1000));3314 Setup_Set_Text_Box(setup_box.script.max_retry_id, custom.queue.max_retry);33153316}33173318function Check_Options_Script_Control() {3319 if(/^\d+$/.test(document.getElementById(setup_box.script.check_interval_id).value) == false) return false;3320 if(/^\d+$/.test(document.getElementById(setup_box.script.check_interval_done_id).value) == false) return false;3321 if(/^\d+$/.test(document.getElementById(setup_box.script.max_send_request_id).value) == false) return false;3322 if(/^\d+$/.test(document.getElementById(setup_box.script.max_wait_limit_id).value) == false) return false;3323 if(/^\d+$/.test(document.getElementById(setup_box.script.max_retry_id).value) == false) return false;33243325 var interval = parseInt(document.getElementById(setup_box.script.check_interval_id).value);3326 var interval_done = parseInt(document.getElementById(setup_box.script.check_interval_done_id).value);3327 var max_send = parseInt(document.getElementById(setup_box.script.max_send_request_id).value);3328 var max_wait = parseInt(document.getElementById(setup_box.script.max_wait_limit_id).value);3329 var max_retry = parseInt(document.getElementById(setup_box.script.max_retry_id).value);3330 if(interval < MIN_INTERVAL) return false;3331 if(interval_done < MIN_INTERVAL) return false;3332 if(max_send < MIN_MAX_SEND) return false;3333 if(max_wait < MIN_MAX_WAIT) return false;3334 if(max_retry < MIN_MAX_RETRY) return false;3335 if(interval > MAX_INTERVAL) return false;3336 if(interval_done > MAX_INTERVAL) return false;3337 if(max_send > MAX_MAX_SEND) return false;3338 if(max_wait > MAX_MAX_WAIT) return false;3339 if(max_retry > MAX_MAX_RETRY) return false;3340 return true;3341}33423343function Save_Options_Script_Control() {3344 custom.queue.check_interval = document.getElementById(setup_box.script.check_interval_id).value * 1000;3345 custom.queue.check_interval_done = document.getElementById(setup_box.script.check_interval_done_id).value * 1000;3346 custom.queue.max_send_request = document.getElementById(setup_box.script.max_send_request_id).value;3347 custom.queue.max_wait_limit = document.getElementById(setup_box.script.max_wait_limit_id).value * 1000;3348 custom.queue.max_retry = document.getElementById(setup_box.script.max_retry_id).value;3349 SetSetupDataScriptControl();33503351}33523353function Save_Options_Others() {3354 SetSetupDataStyle();3355 SetSetupDataOthers();3356}33573358function Player_Visible(mode) {3359 var node = document.getElementById(video_panel.box.id);3360 if(node) {3361 if(mode == true) {3362 node.style.visibility = '';3363 } else {3364 node.style.visibility = 'hidden';3365 }3366 }3367}336833693370function Close_Box() {3371 var base = document.getElementById(setup_box.base.id);3372 setDragObject(null);3373 document.body.removeChild(base);3374 Player_Visible(true);3375}337633773378// Execute download3379function Video_Download(){3380 Change();3381 if(!added_box_watch.original.download_url) {3382 return;3383 }3384 window.location.href=added_box_watch.original.download_url;3385}33863387// Copy from AOK's JavaScript Library. Thanks AOK.3388function _from_utf8(s) {3389 var c, d = "", flag = 0, tmp;3390 for (var i = 0; i < s.length; i++) {3391 c = s.charCodeAt(i);3392 if (flag == 0) {3393 if ((c & 0xe0) == 0xe0) {3394 flag = 2;3395 tmp = (c & 0x0f) << 12;3396 } else if ((c & 0xc0) == 0xc0) {3397 flag = 1;3398 tmp = (c & 0x1f) << 6;3399 } else if ((c & 0x80) == 0) {3400 d += s.charAt(i);3401 } else {3402 flag = 0;3403 }3404 } else if (flag == 1) {3405 flag = 0;3406 d += String.fromCharCode(tmp | (c & 0x3f));3407 } else if (flag == 2) {3408 flag = 3;3409 tmp |= (c & 0x3f) << 6;3410 } else if (flag == 3) {3411 flag = 0;3412 d += String.fromCharCode(tmp | (c & 0x3f));3413 } else {3414 flag = 0;3415 }3416 }3417 return d;3418}34193420// I created this check routine from _from_utf83421function _is_utf8(s) {3422 var c, flag = 0;3423 var utf8 = false;3424 for (var i = 0; i < s.length; i++) {3425 c = s.charCodeAt(i);3426 if (flag == 0) {3427 if ((c & 0xe0) == 0xe0) {3428 flag = 2;3429 } else if(c >= 0xc2 && c <= 0xdf) {3430 flag = 1;3431 } else {3432 flag = 0;3433 }3434 } else if (flag == 1) {3435 if(c >= 0x80 && c <= 0xBF) {3436 utf8 = true;3437 }3438 flag = 0;3439 } else if (flag == 2) {3440 flag = 3;3441 } else if (flag == 3) {3442 if(c >= 0x80 && c <= 0xBF) {3443 utf8 = true;3444 }3445 flag = 0;3446 } else {3447 flag = 0;3448 }3449 }3450 return utf8;3451}34523453function SizeToString(bytesize) {3454 var size_kb = Math.round(bytesize / 1024 * 100)/100;3455 var size_mb = Math.round(bytesize / (1024*1024) * 100)/100;3456 var size_gb = Math.round(bytesize / (1024*1024*1024) * 100)/100;3457 var size = '';3458 if(size_gb >= 1) {3459 size = size + size_gb + ' GB';3460 } else if(size_mb >= 1) {3461 size = size + size_mb + ' MB';3462 } else {3463 size = size + size_kb + ' KB';3464 }3465 if(custom.list.filesize_byte) {3466 size = size + '(' + bytesize + ' B)';3467 }3468 return size;3469}347034713472////// for update checker3473var force_check = false;34743475function IsNecessaryUpdateCheck() {3476 var now = new Date();3477 var now_yy = now.getYear();3478 var now_mm = now.getMonth();3479 var now_dd = now.getDate();3480 var now_day = now.getDay();3481 var dist = now.getTime()/(1000 * 60 * 60 * 24) - update_check.last_check_date/(1000 * 60 * 60 * 24);3482 dist = Math.floor(dist);34833484 var prev = new Date();3485 prev.setTime(update_check.last_check_date);3486 var yy = prev.getYear();3487 var mm = prev.getMonth();3488 var dd = prev.getDate();3489 var day = prev.getDay();34903491 switch(update_check.type) {3492 case ONCE_A_DAY:3493 if(yy != now_yy ||3494 mm != now_mm ||3495 dd != now_dd) return true;3496 break;3497 case ONCE_A_WEEK:3498 if(update_check.specified_day == ANY_DAY) {3499 if(day > now_day) {3500 return true;3501 } else if(day == now_day) {3502 if(yy != now_yy ||3503 mm != now_mm ||3504 dd != now_dd) return true;3505 } else {3506 if(now_day < dist) return true;3507 }3508 } else 3509 if(update_check.specified_day == now_day) {3510 if(yy != now_yy ||3511 mm != now_mm ||3512 dd != now_dd) return true;3513 }3514 break;3515 case ONCE_A_MONTH:3516 if(yy != now_yy) return true;3517 if(mm != now_mm) return true;3518 break;3519 }3520 return false;3521}35223523function ParseScriptPage(text)3524{3525 var data = {version:'', title:"Unknown" };3526 var div = document.createElement('div');3527 div.innerHTML = text;35283529 var node = document.evaluate('.//h1[@class="title"]', div, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;3530 if(node) {3531 data.title = node.textContent;3532 }35333534 var node = document.evaluate('.//*[@id="summary"]', div, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;3535 if(node) {3536 var ver = node.textContent.match(/Version:[\n|\s]*(.*?)\n/)[1];3537 if(ver) {3538 data.version = ver;3539 }3540 }35413542 return data;35433544}35453546function CheckScriptVersion(version) {3547 var work = THIS_VER.split('.');3548 var major_ver = parseInt(work[0]);3549 var minor_ver = parseInt(work[1]);3550 var sub_ver = 0;3551 if(work[2]) sub_ver = parseInt(work[2]);3552 work = version.split('.');3553 var major_ver_uso = parseInt(work[0]);3554 var minor_ver_uso = parseInt(work[1]);3555 var sub_ver_uso = 0;3556 if(work[2]) sub_ver_uso = parseInt(work[2]);3557 if(major_ver < major_ver_uso) {3558 return true;3559 }3560 if(major_ver == major_ver_uso &&3561 minor_ver < minor_ver_uso) {3562 return true;3563 }3564 if(major_ver == major_ver_uso &&3565 minor_ver == minor_ver_uso &&3566 sub_ver < sub_ver_uso) {3567 return true;3568 }3569 return false;3570}35713572function DispMessage(title, html, base_style) {3573 var base = document.createElement('div');3574 base.id = MSGBOX_ID;3575 base.setAttribute('style', 'position:fixed;top:0px;left:0px;height:60px;padding-right:140px;z-index:200000;'+base_style);3576 var node = document.createElement('div');3577 node.innerHTML = title + " (V"+THIS_VER+")";3578 node.setAttribute('style', 'color:#000000;font-size:20px;margin-left:10px;height:30px;');3579 base.appendChild(node);3580 node = document.createElement('div');3581 node.innerHTML = html;3582 node.setAttribute('style', 'color:#000000;font-size:20px;margin-left:10px;height:30px;');3583 base.appendChild(node);35843585 var setup = document.createElement('input');3586 setup.type = "button";3587 setup.value = "Set up";3588 setup.addEventListener('click', Setup, false);3589 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;');3590 base.appendChild(setup);35913592 var close = document.createElement('input');3593 close.type = "button";3594 close.value = "X";3595 close.addEventListener('click', function(e) {3596 var id = MSGBOX_ID;3597 var node = document.getElementById(id);3598 if(node) {3599 node.parentNode.removeChild(node);3600 }3601 update_check.last3602 }, false);3603 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;');3604 base.appendChild(close);36053606 document.body.appendChild(base);3607}36083609function DispUpdateCheckError(data) {3610 var html = "Can't get script information from USO."+'Visit <a href="'+THIS_URL+'" style="text-decoration:underline;color:#0044FF;">the script page</a>.</span>';3611 DispMessage(data.title, html, "background-color:#FF00FF;");3612}36133614function DispUpdateMessage(data) {3615 var html = 'V'+data.version+' has been released. Visit <a href="'+THIS_URL+'" style="text-decoration:underline;color:#0044FF;">the script page</a>.</span>';3616 DispMessage(data.title, html, "background-color:#FFFF00;");3617}36183619function DispNoUpdateMessage(data) {3620 var html = 'A new version has not been released.';3621 DispMessage(data.title, html, "background-color:#00FFFF;");3622}36233624function ExecuteUpdateCheck() {3625 setTimeout(function(){3626 GM_xmlhttpRequest({3627 method:"GET",3628 url: THIS_URL,3629 headers:{3630 "User-Agent": "Mozilla/4.0 (compatible; MSIE 6.0; Win32)",3631 "Accept":"*/*",3632 "Accept-Language":"en-us"3633 },3634 onload: function(xhr){3635 var text = xhr.responseText;3636 if ( xhr.status != 200 ) { // failed3637 var data = {title: "HTTP Error "+xhr.status, version:""};3638 DispUpdateCheckError(data);3639 GM_log(xhr.status + ': ' + text);3640 return;3641 }3642 update_check.last_check_date = (new Date()).getTime();3643 SetSetupDataUpdateCheck();3644 var data = ParseScriptPage(text);3645 if(data.version) {3646 if(CheckScriptVersion(data.version)) {3647 DispUpdateMessage(data);3648 } else if(force_check == true){3649 DispNoUpdateMessage(data);3650 force_check = false;3651 }3652 } else {3653 DispUpdateCheckError(data);3654 }3655 }3656 });3657 },0);3658}36593660function UpdateCheck(mode) {3661 if(mode == true) {3662 ExecuteUpdateCheck();3663 } else {3664 switch(update_check.type) {3665 case NO_CHECK:3666 break;3667 case EVERY_LOADING:3668 ExecuteUpdateCheck();3669 break;3670 case ONCE_A_DAY:3671 case ONCE_A_WEEK:3672 case ONCE_A_MONTH:3673 if(IsNecessaryUpdateCheck()) {3674 ExecuteUpdateCheck();3675 }3676 break;3677 }3678 }3679}36803681function Update_Check_Force() {3682 force_check = true;3683 UpdateCheck(true);3684}36853686function Make_Html_For_Update_Checker() {3687 var html = ''+3688 '<ul style="'+setup_box.update.ul_style+'"><b>About check pattern</b><br />' +3689 '<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>' +3690 '<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>' +3691 '<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>' +3692 '<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>' +3693 '<div id="'+setup_box.update.day_box_id+'" style="'+setup_box.update.day_box_style+'">' +3694 '<ul style="'+setup_box.update.ul_style+'">' +3695 '<li style="'+setup_box.update.li_style+'">' +3696 '<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.any_day_id+'">Any day' +3697 '<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.sunday_id+'">Sunday' +3698 '<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.monday_id+'">Monday' +3699 '<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.tuesday_id+'">Tuesday' +3700 '</li>'+3701 '<li style="'+setup_box.update.li_style+'">'+3702 '<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.wednesday_id+'">Wednesday' +3703 '<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.thursday_id+'">Thursday' +3704 '<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.friday_id+'">Friday' +3705 '<input type="radio" name="'+setup_box.update.day_name+'" id="'+setup_box.update.saturday_id+'">Saturday' +3706 '</li>'+3707 '</ul>'+3708 '</div>'+3709 '<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>' +3710 '</ul>'+3711 '';3712 return html;3713}37143715function Setup_Update_Check() {37163717 Setup_Set_Radio_Button(setup_box.update.no_check_id, (update_check.type == NO_CHECK));3718 Setup_Set_Radio_Button(setup_box.update.every_loading_id, (update_check.type == EVERY_LOADING));3719 Setup_Set_Radio_Button(setup_box.update.once_a_day_id, (update_check.type == ONCE_A_DAY));3720 Setup_Set_Radio_Button(setup_box.update.once_a_week_id, (update_check.type == ONCE_A_WEEK));3721 Setup_Set_Radio_Button(setup_box.update.once_a_month_id, (update_check.type == ONCE_A_MONTH));3722 Setup_Set_Radio_Button(setup_box.update.any_day_id, (update_check.specified_day == ANY_DAY));3723 Setup_Set_Radio_Button(setup_box.update.sunday_id, (update_check.specified_day == SUNDAY));3724 Setup_Set_Radio_Button(setup_box.update.monday_id, (update_check.specified_day == MONDAY));3725 Setup_Set_Radio_Button(setup_box.update.tuesday_id, (update_check.specified_day == TUESDAY));3726 Setup_Set_Radio_Button(setup_box.update.wednesday_id, (update_check.specified_day == WEDNESDAY));3727 Setup_Set_Radio_Button(setup_box.update.thursday_id, (update_check.specified_day == THURSDAY));3728 Setup_Set_Radio_Button(setup_box.update.friday_id, (update_check.specified_day == FRIDAY));3729 Setup_Set_Radio_Button(setup_box.update.saturday_id, (update_check.specified_day == SATURDAY));37303731}37323733function Check_Options_Update_Checker() {3734 return true;3735}37363737function Save_Options_Update_Checker() {37383739 var type;3740 if(document.getElementById(setup_box.update.no_check_id).checked == true) {3741 type = NO_CHECK;3742 } else3743 if(document.getElementById(setup_box.update.every_loading_id).checked == true) {3744 type = EVERY_LOADING;3745 } else3746 if(document.getElementById(setup_box.update.once_a_day_id).checked == true) {3747 type = ONCE_A_DAY;3748 } else3749 if(document.getElementById(setup_box.update.once_a_week_id).checked == true) {3750 type = ONCE_A_WEEK;3751 } else3752 if(document.getElementById(setup_box.update.once_a_month_id).checked == true) {3753 type = ONCE_A_MONTH;3754 }3755 update_check.type = type;37563757 var day;3758 if(document.getElementById(setup_box.update.any_day_id).checked == true) {3759 day = ANY_DAY;3760 } else3761 if(document.getElementById(setup_box.update.sunday_id).checked == true) {3762 day = SUNDAY;3763 } else3764 if(document.getElementById(setup_box.update.monday_id).checked == true) {3765 day = MONDAY;3766 } else3767 if(document.getElementById(setup_box.update.tuesday_id).checked == true) {3768 day = TUESDAY;3769 } else3770 if(document.getElementById(setup_box.update.wednesday_id).checked == true) {3771 day = WEDNESDAY;3772 } else3773 if(document.getElementById(setup_box.update.thursday_id).checked == true) {3774 day = THURSDAY;3775 } else3776 if(document.getElementById(setup_box.update.friday_id).checked == true) {3777 day = FRIDAY;3778 } else3779 if(document.getElementById(setup_box.update.saturday_id).checked == true) {3780 day = SATURDAY;3781 } else {3782 return; // bug3783 }3784 update_check.specified_day = day;37853786 SetSetupDataUpdateCheck();37873788}3789 ...

Full Screen

Full Screen

ProductCatalogWidget.js

Source:ProductCatalogWidget.js Github

copy

Full Screen

1// ProductCatalogWidget.js2 //Public constants3 CATALOG_ID_PREFIX = "Catalog:";4 ACTION_ID_PREFIX = "Action:";5 CATALOG_URI_PROPERTY_NAME = "CatalogHierarchy";6 CATALOG_TRANSFORMATION_URI_PROPERTY_NAME = "CatalogToTreeTransformationSchema";7 PRODUCT_CATALOG_FORM_NAME = "ProductCatalogForm";8 DELETE_CAPTION = "DeleteCaption";9 TREEDEL_CAPTION = "DeleteTree";10 UP_CAPTION = "Up";11 DOWN_CAPTION = "Down";12 NEW_CAPTION = "New";13 INSERT_CAPTION = "Insert";14 RENAME_CAPTION = "Rename";15 COPY_CAPTION = "Copy";16 MOVE_CAPTION = "Move";17 SEARCH_CAPTION = "Search"; 18 NAME_CAPTION = " Name";19 TARGETPATH_CAPTION = "TargetPath";20 FIND_CAPTION = "Find";21 FIND_IN_CAPTION = "FindInCaption";22 23 SELECTED_ELEMENT_NAME_ID = "SelectedCatalogElementNameId";24 SELECTED_ELEMENT_DESCRIPTION_ID = "SelectedCatalogElementDescriptionId";25 SELECTED_ELEMENT_IMAGES_ID = "SelectedCatalogElementImageId";26 SELECTED_ELEMENT_DOCUMENTS_ID = "SelectedCatalogElementDocumentsId";27 28function ProductCatalogWidget( theController, theCatalogDataUri, theName ) {29 //check parameter assertions30 AssertUtil.assertParamNotNull( theController, "theController" );31 AssertUtil.assertParamNotNull( theCatalogDataUri, "theCatalogDataUri");32 //Private constants33 SELECTED_SEPARATOR = ".";34 CATALOG_ELEMENT_CATALOG = "ProductCatalog";35 CATALOG_ELEMENT_ROOT_CATEGORY = "RootCategory";36 CATALOG_ELEMENT_COMPOSITE_CATEGORY = "CompositeCategory";37 CATALOG_ELEMENT_PRODUCT_GROUP = "ProductGroup";38 39 //private instance variables40 var logger = null;41 var containerElement = null;42 var self = this;43 var name = ( theName != null && theName != "" ) ? theName : "ProductCatalogWidget";44 var uiController = theController;45 var i18Resource = uiController.getResourceBundle();46 var configuration = uiController.getApplicationConfiguration();47 var catalogDataUri = theCatalogDataUri;48 var catalogXML = null;49 var selectedCatalogElementType = null;50 var pictureFolder = "images";51 var catalogFormElement = null;52 var propertiesArea = null;53 var subCategoriesArea = null;54 var subCategoriesTableContainer = null;55 var subCategoriesTable = null;56 var searchResultTableContainer = null; 57 var searchResultArea = null; 58 var searchResultTable = null;59 var selectedCatalogItemSpanElement = null;60 var selectedCatalogItemAnchorElement = null;61 var selectedCatalogItemTextElement = null;62 var selectedCatalogItemId = null;63 var selectedCatalogItemName = null;64 var catalogTreeWidget = null;65 var isVisible = false;66 67 //---bo-new html tag vars68 69 var deleteButton = null;70 var deleteTreeButton = null;71 var upButton = null;72 var downButton = null;73 var newButton = null;74 var insertButton = null;75 var renameButton = null;76 var copyButton = null;77 var moveButton = null;78 79 var nameEditBox = null;80 81 var collapsibleElement = null;82 var fieldSet = null;83 var editDiv = null;84 var collapsibleSearchElement = null;85 var searchFieldSet = null;86 var searchDiv = null;87 var searchEditBox = null;88 var searchButton = null;89 90 var collapsibleQuickSearchElement = null;91 var quickSearchFieldSet = null;92 var quickSearchDiv = null;93 var quickSearchEditBox = null;94 var quickSearchSelect = null;95 var quickSearchButton = null;96 // initialization97 if( theName != null && theName != "" ) containerElement = document.getElementById( theName );98 // inherit from BrowserWidget99 var parent = new BrowserWidget( document, containerElement, theController.getResourceBundle() );100 inheritFrom(this, parent);101 102 //public accessor methods103 this.isVisible = function () { return isVisible; }104 this.getCatalogTreeWidget = function () {return catalogTreeWidget;}105 106 //public mutator methods107 this.setPictureFolder = function( folder ) { pictureFolder = folder; }108 this.show = _Show;109 this.hide = _Hide;110 111 _Constructor();112 113 //Constructors114 function _Constructor() {115 configureRootLogger();116 logger = log4javascript.getLogger( ROOT_LOGGER_NAME + ".productCatalogWidget" );117 logger.debug( "New 'ProductCatalogWidget' was instantiated. name:" + name );118 }119 120 //private methods121 function _Show () {122 _ConstructProductCatalogForm();123 logger.trace( "Show with images from:'" + pictureFolder + "'." );124 isVisible = true;125 }126 127 function _Hide () {128 _RemoveTreeWidget();129 isVisible = false;130 }131 132 //HTML construction methods133 function _ConstructCatalogTreeRow( readOnlyContainer ) {134 var label = self.createRowLabelElement( "ui.PlanManagerWidget.Tree.Label" );135 var value = self.createRowValueElement();136 137 var area = self.createElement("div");138 area.id="CatalogTreeWidget";139 area.style.border="1px dotted";140 value.appendChild(area);141 self.insertRow( readOnlyContainer, label, value );142 catalogTreeWidget = new TreeWidget( area, self.getHtmlDOMDocument() );143 }144 function _ConstructEditDiv(readOnlyContainer) {145 collapsibleElement = self.createCollapsibleElement(readOnlyContainer);146 fieldSet = self.createFieldSet(collapsibleElement, "imageIdentifier")147 editDiv = self.createHiddenDiv(fieldSet, "division");148 149 var img = document.getElementById("imageIdentifier");150 img.onclick = function() {151 var collapsibleDiv = document.getElementById(editDiv.id);152 if (collapsibleDiv.style.display == 'none') {153 collapsibleDiv.style.display = 'block';154 img.src = pictureFolder + "/images/collver.png";155 }156 else {157 collapsibleDiv.style.display = 'none';158 img.src = pictureFolder + "/images/expver.png";159 }160 }161 img.setAttribute("src", pictureFolder + "/images/collver.png");162 collapsibleElement.appendChild(fieldSet);163 fieldSet.appendChild(editDiv);164 165 deleteButton = self.createButton( DELETE_CAPTION, _OnDeleteActionClick );166 deleteTreeButton = self.createButton( TREEDEL_CAPTION, _OnDeleteActionClick );167 upButton = self.createButton( UP_CAPTION, _OnDeleteActionClick );168 downButton = self.createButton( DOWN_CAPTION, _OnDeleteActionClick );169 newButton = self.createButton( NEW_CAPTION, _OnNewActionClick );170 insertButton = self.createButton( INSERT_CAPTION, _OnInsertActionClick );171 renameButton = self.createButton( RENAME_CAPTION, _OnRenameActionClick );172 copyButton = self.createButton( COPY_CAPTION, _OnCopyActionClick );173 moveButton = self.createButton( MOVE_CAPTION, _OnMoveActionClick );174 var label1 = self.createRowLabelElement("");175 var row1 = self.createRowValueElement();176 row1.appendChild( copyButton );177 row1.appendChild( moveButton );178 row1.appendChild( upButton );179 row1.appendChild( downButton );180 self.insertRow(editDiv, label1, row1);181 var nameLabel = self.createRowLabelElement(NAME_CAPTION);182 var row = self.createRowValueElement();183 nameEditBox = self.createElement( "INPUT" );184 nameEditBox.type = "text";185 row.appendChild( nameEditBox );186 row.appendChild(newButton);187 row.appendChild(insertButton);188 row.appendChild(renameButton);189 self.insertRow(editDiv, nameLabel, row);190 var label2 = self.createRowLabelElement("");191 var row2 = self.createRowValueElement();192 row2.appendChild( deleteButton );193 row2.appendChild( deleteTreeButton );194 self.insertRow(editDiv, label2, row2);195 196 editDiv.appendChild(self.createElement("BR"));197 editDiv.appendChild(self.createElement("BR"));198 199 self.insertReadOnlyContainer(collapsibleElement);200 }201 202 function _ConstructProductCatalogForm () {203 var catalogFormElement = self.appendFormElement ( PRODUCT_CATALOG_FORM_NAME, "POST" );204 var readOnlyContainer = self.insertReadOnlyContainer( catalogFormElement );205 _ConstructQuickSearchForm( readOnlyContainer );206 //_ConstructSearchForm(readOnlyContainer);207 _ConstructCatalogTreeRow( readOnlyContainer );208 _ConstructPropertiesArea( readOnlyContainer );209 _ConstructSubCategoriesArea( readOnlyContainer );210 _ConstructEditDiv( readOnlyContainer );211 212 if( uiController != null && uiController != "" ) catalogTreeWidget.setResourceBundle( uiController.getResourceBundle() );213 catalogTreeWidget.setSourceXmlFileName( catalogDataUri );214 catalogTreeWidget.setTransformationXslFileName( configuration.getProperty( CATALOG_TRANSFORMATION_URI_PROPERTY_NAME ));215 catalogTreeWidget.setPictureFolder( pictureFolder );216 catalogTreeWidget.loadWidget();217 catalogTreeWidget.showWidget();218 catalogTreeWidget.functionInSelect = _OnCatalogClick;219 220 catalogXML = catalogTreeWidget.getSourceXML();221 _RefreshSelectedCatalogElementProperties(); 222 return readOnlyContainer;223 }224 225 function _ConstructPropertiesArea( readOnlyContainer ) {226 propertiesArea = self.createDivisionElement( readOnlyContainer );227 228 var label = self.createRowLabelElement( "ui.PlanManagerWidget.SelectedItem.Label" );229 selectedCatalogItemSpanElement = self.createRowValueElement();230 selectedCatalogItemAnchorElement = self.createAnchor( 0, "", _OnSelectedCatalogItemClick );231 selectedCatalogItemTextElement = selectedCatalogItemAnchorElement.firstChild;232 selectedCatalogItemSpanElement.appendChild( selectedCatalogItemAnchorElement );233 selectedCatalogItemSpanElement.appendChild( self.createElement( "BR" ));234 self.insertRow( propertiesArea, label, selectedCatalogItemSpanElement );235 self.appendStaticRow( propertiesArea, "ui.PlanManagerWidget.SelectedItem.Name.Label", "-", SELECTED_ELEMENT_NAME_ID );236 self.appendStaticRow( propertiesArea, "ui.PlanManagerWidget.SelectedItem.Description.Label", "-", SELECTED_ELEMENT_DESCRIPTION_ID );237 self.appendStaticRow( propertiesArea, "ui.PlanManagerWidget.SelectedItem.Images.Label", "-", SELECTED_ELEMENT_IMAGES_ID );238 self.appendStaticRow( propertiesArea, "ui.PlanManagerWidget.SelectedItem.Documents.Label", "-", SELECTED_ELEMENT_DOCUMENTS_ID );239 }240 241 function _ConstructSearchResultArea( readOnlyContainer ) {242 var label = self.createRowLabelElement( "ui.PlanManagerWidget.SearchResultList.Label" );243 searchResultTableContainer = self.createRowValueElement(); 244 searchResultArea = self.insertRow( readOnlyContainer, label, searchResultTableContainer ); 245 }246 247 function _ConstructSubCategoriesArea( readOnlyContainer ) {248 var label = self.createRowLabelElement( "ui.PlanManagerWidget.CatalogEntryList.Label" );249 subCategoriesTableContainer = self.createRowValueElement(); 250 subCategoriesArea = self.insertRow( readOnlyContainer, label, subCategoriesTableContainer );251 }252 253 function _ConstructQuickSearchForm( readOnlyContainer ) {254 collapsibleQuickSearchElement = self.createCollapsibleElement( readOnlyContainer );255 quickSearchFieldSet = self.createFieldSet( collapsibleQuickSearchElement, "quickSearchFSImage" );256 quickSearchDiv = self.createHiddenDiv( quickSearchFieldSet, "quickSearchDiv" );257 258 var img = document.getElementById("quickSearchFSImage");259 img.onclick = function() {260 var collapsibleDiv = document.getElementById( quickSearchDiv.id );261 if (collapsibleDiv.style.display == 'none') {262 collapsibleDiv.style.display = 'block';263 img.src = pictureFolder + "/images/collver.png";264 }265 else {266 collapsibleDiv.style.display = 'none';267 img.src = pictureFolder + "/images/expver.png";268 }269 }270 img.setAttribute("src", pictureFolder + "/images/collver.png");271 collapsibleQuickSearchElement.appendChild(quickSearchFieldSet);272 quickSearchFieldSet.appendChild(quickSearchDiv);273 274 //---275 searchButton = self.createButton( SEARCH_CAPTION, _OnFreeTextSearchActionClick );276 var searchLabel = self.createRowLabelElement( FIND_CAPTION );277 var searchRow = self.createRowValueElement();278 searchEditBox = self.createElement( "INPUT" );279 280 searchEditBox.type = "text";281 searchRow.appendChild( searchEditBox );282 searchRow.appendChild(searchButton);283 self.insertRow(quickSearchDiv, searchLabel, searchRow);284 quickSearchDiv.appendChild(self.createElement("BR"));285 quickSearchDiv.appendChild(self.createElement("BR"));286 quickSearchDiv.appendChild(self.createElement("BR"));287 //---288 289 var findInLabel = self.createRowLabelElement( FIND_IN_CAPTION );290 var findInRow = self.createRowValueElement();291 quickSearchSelect = self.createElement( "SELECT" );292 var option0 = new Option( "Select...", 0 );293 var option1 = new Option( "Product Id", 1 );294 var option2 = new Option( "Manufacturer code", 2 );295 var option3 = new Option( "EAN", 3 );296 quickSearchSelect.options[0] = option0;297 quickSearchSelect.options[1] = option1;298 quickSearchSelect.options[2] = option2;299 quickSearchSelect.options[3] = option3;300 findInRow.appendChild( quickSearchSelect );301 self.insertRow(quickSearchDiv, findInLabel, findInRow);302 quickSearchButton = self.createButton( SEARCH_CAPTION, _OnQuickSearchActionClick );303 var quickSearchLabel = self.createRowLabelElement(FIND_CAPTION);304 var quickSearchRow = self.createRowValueElement();305 quickSearchEditBox = self.createElement( "INPUT" );306 quickSearchEditBox.type = "text";307 quickSearchRow.appendChild( quickSearchEditBox );308 quickSearchRow.appendChild(quickSearchButton);309 self.insertRow(quickSearchDiv, quickSearchLabel, quickSearchRow);310 quickSearchDiv.appendChild(self.createElement("BR"));311 quickSearchDiv.appendChild(self.createElement("BR"));312 313 self.insertReadOnlyContainer(collapsibleQuickSearchElement);314 //quickSearchDiv.style.display = "block";315 316 _ConstructSearchResultArea( quickSearchDiv );317 }318 function _ConstructSearchForm(readOnlyContainer) {319 collapsibleSearchElement = self.createCollapsibleElement(readOnlyContainer);320 searchFieldSet = self.createFieldSet(collapsibleSearchElement, "searchFSImage")321 searchDiv = self.createHiddenDiv(searchFieldSet, "searchDiv");322 323 var img = document.getElementById("searchFSImage");324 img.onclick = function() {325 var collapsibleDiv = document.getElementById(searchDiv.id);326 if (collapsibleDiv.style.display == 'none') {327 collapsibleDiv.style.display = 'block';328 img.src = pictureFolder + "/images/collver.png";329 }330 else {331 collapsibleDiv.style.display = 'none';332 img.src = pictureFolder + "/images/expver.png";333 }334 }335 collapsibleSearchElement.appendChild(searchFieldSet);336 searchFieldSet.appendChild(searchDiv);337 338 searchButton = self.createButton( SEARCH_CAPTION, _OnSearchActionClick );339 var searchLabel = self.createRowLabelElement(FIND_CAPTION);340 var searchRow = self.createRowValueElement();341 searchEditBox = self.createElement( "INPUT" );342 searchEditBox.setAttribute("id", "searchme");343 344 searchEditBox.type = "text";345 searchRow.appendChild( searchEditBox );346 searchRow.appendChild(searchButton);347 self.insertRow(searchDiv, searchLabel, searchRow);348 searchDiv.appendChild(self.createElement("BR"));349 searchDiv.appendChild(self.createElement("BR"));350 351 self.insertReadOnlyContainer(collapsibleSearchElement);352 }353 354 function _CreateCatalogEntryListHeader( tableDefinition ) {355 tableDefinition.addColumn( "ui.PlanManagerWidget.CatalogEntryList.Column.Identifier" );356 tableDefinition.addColumn( "ui.PlanManagerWidget.CatalogEntryList.Column.Designation" );357 tableDefinition.addColumn( "ui.PlanManagerWidget.CatalogEntryList.Column.Properties" );358 tableDefinition.addColumn( "ui.PlanManagerWidget.CatalogEntryList.Column.Price" );359 }360 361 function _CreateCatalogEntryListRows( catalogEntries, tableDefinition ) {362 logger.trace( "Creating " + catalogEntries.length + " number of CatalogEntry rows.");363 for( var i=0; i < catalogEntries.length; i++ ) {364 var catalogEntryProperties = new Array(4);365 var catalogEntry = catalogEntries[i];366 var catalogEntryXML = new XML( catalogEntry );367 catalogEntryProperties[0] = catalogEntryXML.getNodeValue( "catalogEntryIdentifier" );368 catalogEntryProperties[1] = catalogEntryXML.getNodeValue( "designation" );369 catalogEntryProperties[2] = catalogEntryXML.getNodeValue( "featureDescription" );370 catalogEntryProperties[3] = catalogEntryXML.getNodeValue( "price" );371 372 tableDefinition.addRow( catalogEntryProperties );373 } 374 }375 376 function _DetermineCurrentSelectionBase( selectedTreeNode ) {377 var selectionPath = "";378 379 if( selectedTreeNode != null ) {380 var selectedNodeID = selectedTreeNode.getID();381 logger.trace( "Selected catalog element's id is:", selectedNodeID );382 383 selectionPath = "//catalog[@id=\"" + selectedNodeID + "\"]";384 var selectedCatalogElement = catalogXML.getNode( selectionPath );385 if( selectedCatalogElement != null ) {386 selectedCatalogElementType = CATALOG_ELEMENT_CATALOG;387 }else {388 selectionPath = "//rootCategory[@id=\"" + selectedNodeID + "\"]";389 selectedCatalogElement = catalogXML.getNode( selectionPath );390 if( selectedCatalogElement != null ) {391 selectedCatalogElementType = CATALOG_ELEMENT_ROOT_CATEGORY;392 }else {393 selectionPath = "//compositeCategory[@id=\"" + selectedNodeID + "\"]";394 selectedCatalogElement = catalogXML.getNode( selectionPath );395 if( selectedCatalogElement != null ) {396 selectedCatalogElementType = CATALOG_ELEMENT_COMPOSITE_CATEGORY;397 }else {398 selectionPath = "//productGroup[@id=\"" + selectedNodeID + "\"]";399 selectedCatalogElement = catalogXML.getNode( selectionPath );400 if( selectedCatalogElement != null ) {401 selectedCatalogElementType = CATALOG_ELEMENT_PRODUCT_GROUP;402 }else throw( "The selected tree node:'" + selectedNodeID + "' dosn't exist in catalog XML." );403 }404 }405 }406 } else selectionPath = "//actionResponse/catalog";407 logger.trace("Selected element's type is:", selectedCatalogElementType );408 logger.trace("Selected element's path is:", selectionPath );409 return selectionPath;410 }411 412 function _DetermineProductGroupTableRows( tableDefinition, xpathSelectorBase ) {413 var xPathQuery = xpathSelectorBase + "/catalogEntries/catalogEntry";414 var catalogEntries = catalogXML.getNodes( xPathQuery );415 _CreateCatalogEntryListRows( catalogEntries, tableDefinition );416 }417 418 function _DetermineSearchResultTableRows( tableDefinition, xPathQuery ) {419 try{420 var catalogEntries = catalogXML.getNodes( xPathQuery );421 logger.trace( "XPath query: " + xPathQuery + " returned " + catalogEntries.lenght + " number of rows" );422 _CreateCatalogEntryListRows( catalogEntries, tableDefinition );423 } catch(e) {}424 }425 426 function _DetermineSelectedElementDescription( currentSelectionBase ) {427 var determinedDescription = catalogXML.getNodeValue( currentSelectionBase + "/description" );428 return determinedDescription;429 }430 431 function _DetermineSelectedElementName( currentSelectionBase ) {432 var determinedName = catalogXML.getNodeValue( currentSelectionBase + "/name" );433 return determinedName;434 }435 436 function _DetermineSelectedElementType() {437 return "Type";438 }439 440 function _OnCatalogClick() {441 selectedCatalogItemName = catalogTreeWidget.getSelectedNodeFullCaption();442 var newTextElement = self.createTextNode( selectedCatalogItemName );443 selectedCatalogItemAnchorElement.replaceChild( newTextElement, selectedCatalogItemTextElement );444 selectedCatalogItemTextElement = newTextElement;445 446 selectedCatalogItemId = catalogTreeWidget.getSelectedNode().getID();447 selectedCatalogItemName = catalogTreeWidget.getSelectedNode().getName();448 449 _RefreshSelectedCatalogElementProperties( catalogTreeWidget.getSelectedNode() );450 }451//------TreeEditor----------------------------452 function _OnCopyActionClick() {}453 454 function _OnDeleteActionClick() {455 }456 457 function _OnDeleteTreeActionClick() {}458 function _OnDownActionClick() {}459 460 function _OnInsertActionClick() {}461 462 function _OnFreeTextSearchActionClick() {463 logger.trace( "Searching for CatalogEntry which contains: '" + searchEditBox.value + "'" );464 var xPathQuery = "//catalogEntry[contains( designation/text(), '" + searchEditBox.value + "')]";465 _RefreshSearchResultTable( xPathQuery );466 }467 function _OnMoveActionClick() {}468 function _OnNewActionClick() {}469 function _OnQuickSearchActionClick() {470 var selectedOption = quickSearchSelect.value;471 var xPathQuery = "";472 473 logger.trace( "Searching by:", selectedOption );474 if( selectedOption == 1 ) {475 xPathQuery = "//catalogEntry[@id='" + quickSearchEditBox.value + "']";476 }477 if( selectedOption == 2 ) {478 xPathQuery = "//catalogEntry[producerCode='" + quickSearchEditBox.value + "']";479 } 480 if( selectedOption == 3 ) {481 xPathQuery = "//catalogEntry[eanCode='" + quickSearchEditBox.value + "']";482 }483 484 _RefreshSearchResultTable( xPathQuery ); 485 }486 487 function _OnRenameActionClick() {488 logging( "Searching by ProductTypeIdentifier." );489 }490 491 492 function _OnSelectedCatalogItemClick() {493 }494 495 function _OnUpActionClick() {}496 function _RefreshSearchResultTable( xPathQuery ) {497 logger.trace( "Refreshing search result table with results of query: ", xPathQuery );498 499 self.removeChild( searchResultTableContainer, searchResultTable );500 searchResultTable = null;501 var tableDefinition = new TableDefinition();502 _CreateCatalogEntryListHeader( tableDefinition );503 _DetermineSearchResultTableRows( tableDefinition, xPathQuery );504 searchResultTable = self.createTable( tableDefinition );505 self.appendChild( searchResultTableContainer, searchResultTable ); 506 }507 508 function _RefreshSelectedCatalogElementProperties( selectedTreeNode ) {509 var xpathSelectorBase = _DetermineCurrentSelectionBase( selectedTreeNode );510 511 _RefreshSelectedElementName( xpathSelectorBase );512 _RefreshSelectedElementDescription( xpathSelectorBase );513 _RefreshSelectedProductGroupEntries( xpathSelectorBase );514 }515 516 function _RefreshSelectedElementName( xpathSelectorBase ) {517 var selectedElementName = _DetermineSelectedElementName( xpathSelectorBase );518 self.updateTextNode( propertiesArea, SELECTED_ELEMENT_NAME_ID, selectedElementName );519 }520 521 function _RefreshSelectedElementDescription( xpathSelectorBase ) {522 var selectedElementDescription = _DetermineSelectedElementDescription( xpathSelectorBase );523 self.updateTextNode( propertiesArea, SELECTED_ELEMENT_DESCRIPTION_ID, selectedElementDescription );524 }525 526 function _RefreshSelectedProductGroupEntries( xpathSelectorBase ) {527 self.removeChild( subCategoriesTableContainer, subCategoriesTable );528 subCategoriesTable = null;529 logger.trace( subCategoriesTableContainer, subCategoriesTable );530 531 if( selectedCatalogElementType == CATALOG_ELEMENT_PRODUCT_GROUP ) {532 var tableDefinition = new TableDefinition();533 _CreateCatalogEntryListHeader( tableDefinition );534 _DetermineProductGroupTableRows( tableDefinition, xpathSelectorBase );535 subCategoriesTable = self.createTable( tableDefinition );536 self.appendChild( subCategoriesTableContainer, subCategoriesTable );537 }538 }539 540 function _RemoveTreeWidget () {541 catalogTreeWidget.hideWidget();542 self.removeWidget();543 }544 545 function _SearchIndex() { // search the index (duh!)546 // most current browsers support document.implementation547 if (document.implementation && document.implementation.createDocument) {548 xmlDoc = document.implementation.createDocument("", "", null);549 xmlDoc.load("TestCatalog.xml");550 }551 // MSIE uses ActiveX552 else if (window.ActiveXObject) {553 xmlDoc = new ActiveXObject("Microsoft.XMLDOM");554 xmlDoc.async = "false";555 xmlDoc.load("TestCatalog.xml");556 }557 if (!xmlDoc) {558 loadIndex();559 }560 // get the search term from a form field with id 'searchme'561 562 var searchterm = document.getElementById("searchme").value;563 var allitems = xmlDoc.getElementsByTagName("name");564 results = new Array;565 if (searchterm.length < 3) {566 alert("Enter at least three characters");567 } else {568 for (var i=0;i<allitems.length;i++) {569 var name = allitems[i].lastChild.nodeValue;570 var exp = new RegExp(searchterm,"i");571 if ( name.match(exp) != null) {572 results.push(allitems[i]);573 }574 }575 _ShowResults( results, searchterm );576 }577 }578 579 function _ShowCatalogProperties( elementId ) {580 var label = self.createRowLabelElement( "Kiválasztott katalógus elem:" );581 selectedCatalogSpanElement = self.createRowValueElement();582 selectedCatalogAnchorElement = self.createAnchor( 0, "", _OnSelectedCatalogElementClick );583 selectedCatalogTextElement = selectedCatalogAnchorElement.firstChild;584 selectedCatalogSpanElement.appendChild( selectedCatalogAnchorElement );585 selectedCatalogSpanElement.appendChild( self.createElement( "BR" ));586 self.insertRow( propertiesArea, label, selectedCatalogSpanElement );587 }588 589 function _ShowResults( results, searchterm ) {590 if (results.length > 0) {591 var resultshere = document.getElementById("resultshere");592 var resultFieldSet = document.createElement("fieldSet");593 resultFieldSet.style.width = "65%";594 var legend = document.createElement("legend");595 var textN = document.createTextNode("Keresési eredmény");596 legend.appendChild(textN);597 resultFieldSet.appendChild(legend);598 var header = document.createElement("h5");599 var list = document.createElement("ul");600 var searchedfor = document.createTextNode("You've searched for "+searchterm);601 resultshere.appendChild(header);602 header.appendChild(searchedfor);603 resultshere.appendChild(list);604 resultshere.appendChild(resultFieldSet);605 for (var i=0;i<results.length;i++) {606 var listitem = document.createElement("li");607 var item = document.createTextNode(results[i].lastChild.nodeValue);608 list.appendChild(listitem);609 listitem.appendChild(item);610 }611 } else {612 alert("Search returned with no result for expression: " + searchterm + "!");613 }614 }...

Full Screen

Full Screen

XmlResource.js

Source:XmlResource.js Github

copy

Full Screen

1// XmlResource.js2/**3ProcessPuzzle User Interface4Backend agnostic, desktop like configurable, browser font-end based on MochaUI.5Copyright (C) 2011 Joe Kueser, Zsolt Zsuffa6This program is free software: you can redistribute it and/or modify7it under the terms of the GNU General Public License as published by8the Free Software Foundation, either version 3 of the License, or9(at your option) any later version.10This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.14You should have received a copy of the GNU General Public License15along with this program. If not, see <http://www.gnu.org/licenses/>.16*/17var XmlResource = new Class({18 Extends: Request,19 options: {20 nameSpaces: "xmlns:pp='http://www.processpuzzle.com'",21 22 onComplete: function( responseAsText ) { 23 if( responseAsText ) {24 this.xmlAsText = responseAsText;25 26 if( this.options.parseOnComplete ) {27 this.xmlDoc = Sarissa.getDomDocument(); 28 this.xmlDoc = (new DOMParser()).parseFromString( responseAsText, "text/xml" ); 29 }30 }31 },32 33 onException : function( headerName, value ) {34 //console.log( "Request header failed: '" + value + "'" );35 },36 37 onFailure : function( xhr ) {38 //console.log( "Request failed. status: '" + xhr.status + "'" );39 },40 41 parseOnComplete : true42 },43 44 // Constructor45 initialize: function ( uri, options ) {46 // parameter assertions47 AssertUtil.assertParamNotNull( uri, "uri");48 49 this.parent( options );50 this.options.url = uri;51 this.options.method = 'get';52 this.options.async = false;53 this.xmlAsText = null;54 this.xmlDoc = null;55 this.refreshResource();56 57 //console.log('XmlResource is initialized.');58 },59 60 // Public accessor and mutator methods61 determineAttributeValue : function( xmlElement, attributeName ) {62 return XmlResource.determineAttributeValue( xmlElement, attributeName );63 },64 65 determineNodeText : function( xmlElement ) {66 return XmlResource.determineNodeText( xmlElement );67 },68 69 isSuccess: function() { // Determines if an XMLHttpRequest was successful or not70 try {71 // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #145072 return !this.status && location.protocol === "file:" ||73 // Opera returns 0 when status is 30474 ( this.status >= 200 && this.status < 300 ) ||75 this.status === 304 || this.status === 1223 || this.status === 0;76 } catch(e) {}77 return false;78 },79 80 selectNode : function( selector, subNode ) {81 var selectedNodes = this.selectNodes( selector, subNode );82 if( selectedNodes ) return selectedNodes[0];83 else return null;84 }, 85 86 selectNodes : function( selector, subNode ) {87 var subjectNode = subNode != null ? subNode : this.xmlDoc;88 89 var foundXmlNodes = null;90 try {91 var foundXmlNodes = subjectNode.selectNodes( selector );92 }catch(e) {93 //console.log( e );94 //console.log( "Namespaces: " + subjectNode.getProperty( "SelectionNamespaces" ));95 return null;96 }97 return foundXmlNodes;98 },99 100 selectNodeText : function( selector, subNode ) {101 var selectedElements = this.selectNodes( selector, subNode );102 if( selectedElements.length > 0 && selectedElements[0] ) {103 return selectedElements[0].data;104 }else return null;105 }, 106 107 refreshResource: function(){108 try {109 this.send( this.options.url );110 }catch( e ){111 throw new UndefinedXmlResourceException( this.options.url );112 }113 114 if( this.options.parseOnComplete && this.xmlDoc == null )115 throw new UndefinedXmlResourceException( this.options.url );116 117 if( this.xmlDoc ) {118 this.xmlDoc.setProperty("SelectionNamespaces", "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " + this.options.nameSpaces ); 119 this.xmlDoc.setProperty("SelectionLanguage", "XPath");120 }121 },122 123 transform: function( xslt ){},124 125 // Properties126 getDocument: function() { return this.xmlDoc; },127 getUri: function() { return this.options.url; },128 getXmlAsText: function() { return this.xmlAsText; },129 isAsync: function() { return this.options.async; }130 131 //Private helper methods132});133//Static methods134XmlResource.determineAttributeValue = function( xmlElement, attributeName ) {135 var attributeElement = xmlElement.selectNodes( "@" + attributeName );136 if( attributeElement && attributeElement.length == 1 ) return attributeElement[0].nodeValue;137 else return null;138};139XmlResource.determineNodeText = function( xmlElement ) {140 if( xmlElement ) return Sarissa.getText( xmlElement );141 else return null;142};143XmlResource.selectNode = function( selector, xmlElement ){144 var selectedNodes = XmlResource.selectNodes( selector, xmlElement );145 if( selectedNodes ) return selectedNodes[0];146 else return null;147};148XmlResource.selectNodes = function( selector, xmlElement ){149 var selectedElements = null;150 try{151 selectedElements = xmlElement.selectNodes( selector );152 }catch( e ){153 log4javascript.getDefaultLogger().debug( "Selector: '" + selector + "' caused excection: " + e.message );154 return null;155 }156 return selectedElements;157};158XmlResource.selectNodeText = function( selector, xmlElement, nameSpaces ) {159 var selectedElement = XmlResource.selectNode( selector, xmlElement, nameSpaces );160 return XmlResource.determineNodeText( selectedElement );161};162Browser.Request = function(){163 return $try( function(){164 if( Browser.Engine.trident && window.location.protocol == "file:" )165 return new ActiveXObject('Microsoft.XMLHTTP');166 else 167 return new XMLHttpRequest();168 }, function(){169 return new ActiveXObject('MSXML2.XMLHTTP');170 }, function(){171 return new ActiveXObject('Microsoft.XMLHTTP');172 });173};174function XMLDocument () {175 var xmlDoc = null;176 if(document.implementation && document.implementation.createDocument)177 { xmlDoc = document.implementation.createDocument("", "", null);178 }179 else if( window.ActiveXObject )180 { xmlDoc = new ActiveXObject("Microsoft.XMLDOM");181 xmlDoc.async = false;182 }183 else184 { alert('Your browser can\'t handle this script');185 return;186 }187 188 return xmlDoc;189}190function TransformXML( xmlFileName, xslFileName ) {191 var xml = new XmlResource( xmlFileName );192 var xsl = new XmlResource( xslFileName );193 var resultXml = XMLDocument();194 xml.transformNodeToObject(xsl,resultXml);195 return resultXml;196}197function XMLTransformator( xmlFileName, xslFileName ) {198 var sourceXML = new XML();199 sourceXML.load( xmlFileName );200 201 var xslt = new XSLT( xslFileName );202 203 var resultXML = new XML();204 205 this.getSourceXML = function() { return sourceXML; }206 this.getResultXML = function() { return resultXML; }207 this.transform = _Transform;208 209 function _Transform() {210 resultXML = new XML( xslt.transform( sourceXML ));211 return resultXML.getDOM();212 }213}214function RemoveWhitespaceNodesFromXML( xml ) {215 var notWhitespace = /\S/;216 for( var i=0; i < xml.childNodes.length; i++ ) {217 if(xml.childNodes[i].nodeType == 3 && !notWhitespace.test(xml.childNodes[i].nodeValue)) {218 xml.removeChild(xml.childNodes[i]);219 i--;220 } else RemoveWhitespaceNodesFromXML(xml.childNodes[i]);221 }...

Full Screen

Full Screen

TreeWidget.js

Source:TreeWidget.js Github

copy

Full Screen

1var TreeWidget = new Class({2 //public constants3 NODE_PATH_SEPARATOR : ".",4 5 Extends : BrowserWidget,6 7 // constructor8 initialize: function( domDocument, widgetContainerId, resourceBundle, locale ) {9 10 /***********************************************************************11 * Configuration variables.12 ************************************************************************/13 this.showRootNode = false; // Should the rootNode be displayed.14 this.documentID = window.location.href; // This is IMPORTANT... use an unique id for each document you use the tree in. (else they'll get mixed up).15 this.rootNode = null; // RootNode of the tree.16 17 /************************************************************************18 * The following are just instancevariables.19 ************************************************************************/20 this.logger = null;21 this.states = '';22 this.statearray = new Array();23 this.isLoaded = false;24 this.isVisible = false;25 this.treeDefinitionFileName = "";26 this.sourceXmlFileName = "";27 this.sourceXML = null;28 this.treeDefinitionXML = null;29 this.transformationXslFileName = "";30 this.externalTreeDefinition = null;31 this.pictureFolder = "";32 this.resourceBundle = null;33 this.selectedNameList = null;34 this.selectedNameListSize = 0;35 //Initialization36 this.parent( domDocument, widgetContainerId, resourceBundle, locale );37 this.configureRootLogger();38 this.logger = log4javascript.getLogger( ROOT_LOGGER_NAME + ".treeWidget" );39 this.logger.debug( "New 'TreeWidget' was instantiated." );40 },41 42 //public accessor and mutator methods43 changeCaptions : function() {44 if( this.rootNode != null ) this.rootNode.changeCaption( this.controller );45 },46 47 clearContainerElement : function() {48 while( this.containerElement.hasChildNodes() ) 49 this.containerElement.removeChild( containerElement.childNodes[0] );50 },51 52 getSelectedNode : function() {53 if( this.getSelectedNameListSize() == 0 ) return null;54 return this.rootNode.findNodeByPath( this.getSelectedNodeFullCaption() );55 },56 57 getSelectedNodeFullCaption : function() {58 var list = this.getSelectedNameList();59 var index = this.getSelectedNameListSize();60 var selectedNodeCaption = "";61 while( index > 1 ) { 62 selectedNodeCaption += list[index-1] + this.NODE_PATH_SEPARATOR;63 index--;64 }65 selectedNodeCaption += list[0];66 return selectedNodeCaption;67 },68 69 getText : function ( key ) {70 if( this.resourceBundle != null ) {71 var value = null;72 try {73 value = this.resourceBundle.getText( key );74 }75 catch( e ) {76 value = key;77 }78 return value;79 }80 return key;81 },82 83 hideWidget : function() {84 if( this.rootNode != null ) {85 this.rootNode.hide();86 this.isVisible = false;87 }88 },89 90 loadWidget : function() {91 var treeDefinition = this.getTreeDefinitionXML();92 this.removeWhitespaceNodesFromXML( treeDefinition );93 var rootXmlElements = treeDefinition.getElementsByTagName("RootNode");94 if( rootXmlElements ) {95 this.rootNode = new TreeNode( 1,"RootNode","RootNode","folder","opened" );96 this.rootNode.setHtmlDOMDocument( this.htmlDOMDocument );97 this.rootNode.setPictureFolder( this.pictureFolder );98 this.rootNode.widget = self;99 if( rootXmlElements[0].getAttribute( "visible" ) == "true" ) this.rootNode.setToVisible();100 this.rootNode.setContainerElement(containerElement);101 this.rootNode.hide();102 this.loadNodeFromXML(rootXmlElements[0], rootNode);103 this.makeWidgetTree();104 }105 },106 107 showWidget : function() {108 if( this.rootNode != null ) {109 this.rootNode.show();110 this.isVisible = true;111 }112 },113 114 removeWidgetTree : function() {115 if( this.rootNode != null ) {116 var rootChilds = this.rootNode.getChilds();117 for( var i=0; i < rootChilds.length; i++) {118 var child = rootChilds[i];119 child.removeDivElement();120 }121 this.rootNode = null;122 }123 },124 125 //Properties126 getSelectedNameList : function() { return this.selectedNameList; },127 getSelectedNameListSize : function() { return this.selectedNameListSize; },128 getShowRootNode : function() { return this.showRootNode; },129 getSourceXML : function() { return this.sourceXML; },130 getTreeDefinitionXML : function() { return this.treeDefinitionXML; },131 isLoaded : function() { return this.isLoaded;},132 isVisible : function() { return this.isVisible; },133 setHtmlDOMDocument : function( newHtmlDOMDocument ) { htmlDOMDocument = newHtmlDOMDocument; },134 setResourceBundle : function( newResourceBundle ) { resourceBundle = newResourceBundle; },135 setShowRootNode : function (value) { showRootNode = value; },136 setDefinitionFileName : function ( fileName ) { treeDefinitionFileName = fileName; },137 setSourceXmlFileName : function ( fileName ) { sourceXmlFileName = fileName; },138 setTransformationXslFileName : function ( fileName ) { transformationXslFileName = fileName; },139 setExternalTreeDefinition : function ( extTreeDef ) { externalTreeDefinition = extTreeDef; },140 setPictureFolder : function ( newPictureFolderName ) { pictureFolder = newPictureFolderName; },141 setSelectedNameList : function( list, size ) { 142 selectedNameList = list; 143 selectedNameListSize = size;144 if( this.functionInSelect != null ) this.functionInSelect();145 },146 147 //private methods148 createSpanTagForPrefix : function() {149 return htmlDOMDocument.createElement("span");150 },151 getTreeDefinitionXML : function() {152 if(treeDefinitionFileName != null && treeDefinitionFileName !="")153 return new XmlResource( treeDefinitionFileName );154 else155 if(sourceXmlFileName != null && sourceXmlFileName != "" &&156 transformationXslFileName != null && transformationXslFileName != "") {157 var transformator = new XMLTransformator( sourceXmlFileName, transformationXslFileName );158 treeDefinitionXML = transformator.transform();159 sourceXML = transformator.getSourceXML();160 return treeDefinitionXML;161 }162 else if( externalTreeDefinition != null && externalTreeDefinition != "" ) return externalTreeDefinition;163 else throw new UndefinedTreeDefinitionException();164 },165 //Adds a series of nodes to a given tree node based on xml tree definition166 loadNodeFromXML : function( xmlElement, treeNodeToAdd ) {167 for(var n = 0; n < xmlElement.childNodes.length; n++) { //a "var"-ok fontosak a rekurzio miatt!!!168 var element = xmlElement.childNodes[n];169 if (element.attributes!=null) {170 var theUrl = element.getAttribute("url");171 var caption = element.getAttribute("caption");172 var captionText = this.getText( caption );173 var childNode = new TreeNode( element.getAttribute("nodeId"), caption, captionText, element.getAttribute("type"), element.getAttribute("state"), theUrl, element.getAttribute("target"), element.getAttribute("image"), element.getAttribute("image2"));174 childNode.setHtmlDOMDocument(htmlDOMDocument);175 childNode.setPictureFolder(pictureFolder);176 if (element.getAttribute("selectable")=="true") childNode.setSelectable(true);177 treeNodeToAdd.addChild(childNode);178 }179 if( element.hasChildNodes ) this.loadNodeFromXML( element, childNode );180 }181 return;182 },183 makeWidgetTree : function() {184 if (rootNode!=null) {185 if(rootNode.isVisible()) 186 rootNode.make(null);187 var prefix = createSpanTagForPrefix();188 for(i=0; i<rootNode.getChildCount(); i++) { rootNode.getChilds()[i].make(prefix); }189 }190 }...

Full Screen

Full Screen

source.js

Source:source.js Github

copy

Full Screen

...9 return await this.executeAtom('execute_script', [script, []]);10 }11 if ((await this.settings.getSettings()).useJSONSource) {12 let srcTree = await this.mobileGetSource({format: 'json'});13 return getSourceXml(getTreeForXML(srcTree));14 }15 return await this.getNativePageSource();16};17helpers.getNativePageSource = async function getNativePageSource () {18 let srcTree = await this.proxyCommand('/source', 'GET');19 let parser = new xmldom.DOMParser();20 let tree = parser.parseFromString(srcTree);21 let doc = parser.parseFromString(APPIUM_SRC_XML);22 doc.documentElement.appendChild(tree.documentElement);23 return new xmldom.XMLSerializer().serializeToString(doc);24};25helpers.mobileGetSource = async function mobileGetSource (opts = {}) {26 if (!_.isString(opts.format)) {27 return await this.getNativePageSource();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio')2const opts = {3 capabilities: {4 },5}6async function runTest() {7 const client = await remote(opts)8 const source = await client.getSource()9 console.log(source)10}11runTest()12const { remote } = require('webdriverio')13const opts = {14 capabilities: {15 },16}17async function runTest() {18 const client = await remote(opts)19 const source = await client.getSourceXml()20 console.log(source)21}22runTest()23const { remote } = require('webdriverio')24const opts = {25 capabilities: {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio')2const opts = {3 capabilities: {4 },5}6async function runTest() {7 const client = await remote(opts)8 const source = await client.getSource()9 console.log(source)10}11runTest()12const { remote } = require('webdriverio')13const opts = {14 capabilities: {15 },16}17async function runTest() {18 const client = await remote(opts)19 const source = await client.getSourceXml()20 console.log(source)21}22runTest()23const { remote } = require('webdriverio')24const opts = {25 capabilities: {

Full Screen

Using AI Code Generation

copy

Full Screen

1console.log(source);2var source = driver.getPageSource();3console.log(source);4var source = driver.getPageSource();5console.log(source);6var source = driver.getPageSource();7console.log(source);8var source = driver.getPageSource();9console.log(source);10var source = driver.getPageSource();11console.log(source);12var source = driver.getPageSource();13console.log(source);14var source = driver.getPageSource();15console.log(source);16var source = driver.getPageSource();17console.log(source);18var source = driver.getPageSource();19console.log(source);20var source = driver.getPageSource();21console.log(source);22var source = driver.getPageSource();23console.log(source);24var source = driver.getPageSource();25console.log(source);26var source = driver.getPageSource();27console.log(source);28var source = driver.getPageSource();29console.log(source);30var source = driver.getPageSource();31console.log(source);32var source = driver.getPageSource();33console.log(source);34var source = driver.getPageSource();35console.log(source);

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new iosDriver({2});3driver.getSourceXml().then(function(srcXml) {4 console.log(srcXml);5});6driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var driver = new iosDriver({2});3driver.getSourceXml().then(function(srcXml) {4 console.log(srcXml);5});6driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const { exec } = require('child_process');3const path = require('path');4const xml2js = require('xml2js');5const { Builder, By, Capabilities, until } = require('selenium-webdriver');6const { XCUITestDriver } = require('appium-xcuitest-driver');7const caps = {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful