MassiveFap

A complete ImageFap.com gallery conversion script featuring customization options and multiple viewing modes.

Ajankohdalta 21.9.2020. Katso uusin versio.

  1. // ==UserScript==
  2. // @name MassiveFap
  3. // @author Ryan Thaut
  4. // @description A complete ImageFap.com gallery conversion script featuring customization options and multiple viewing modes.
  5. // @namespace https://greasyfork.org/users/408380
  6. // @include https://*imagefap.com/*
  7. // @version 1.6
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_addStyle
  12. // ==/UserScript==
  13.  
  14.  
  15.  
  16. /* ===== Integration =====
  17. This is where the initial/basic eventListeners are added.
  18. */
  19. window.addEventListener('load', init, false);
  20. document.addEventListener('DOMContentLoaded', init, false);
  21.  
  22.  
  23.  
  24. /* ===== Global Variables =====
  25. Changing these is a terrible idea; they are NOT for configuration
  26. */
  27. var fullscreen = false;
  28. var loaded = false;
  29. var images = [];
  30. var head, body, title, addFavLink;
  31. var author = {name: '', url: ''};
  32. var activeImage = (parseInt(getHashParam('image'), 10) - 1) || 0;
  33. var totalImages = 0;
  34. var hotkeys = [
  35. {
  36. action: displayHelp,
  37. codes: [191],
  38. keys: '?',
  39. label: 'Display Help',
  40. modif: {altKey: false, ctrlKey: false, metaKey: false, shiftKey: true}
  41. },
  42. {
  43. action: displayAbout,
  44. codes: [65],
  45. keys: 'a',
  46. label: 'Display About',
  47. modif: {altKey: false, ctrlKey: false, metaKey: false, shiftKey: false}
  48. },
  49. {
  50. action: toggleFullScreen,
  51. codes: [70],
  52. keys: 'f',
  53. label: 'Toggle Full Screen',
  54. modif: {altKey: false, ctrlKey: false, metaKey: false, shiftKey: false}
  55. },
  56. {
  57. action: switchGalleryMode,
  58. codes: [71],
  59. keys: 'g',
  60. label: 'Switch Gallery Mode',
  61. modif: {altKey: false, ctrlKey: false, metaKey: false, shiftKey: false}
  62. },
  63. {
  64. action: changeSettings,
  65. codes: [83],
  66. keys: 's',
  67. label: 'Change Settings',
  68. modif: {altKey: false, ctrlKey: false, metaKey: false, shiftKey: false}
  69. },
  70. {
  71. action: toggleThumbs,
  72. codes: [84],
  73. keys: 't',
  74. label: 'Change Thumbnails',
  75. modif: {altKey: false, ctrlKey: false, metaKey: false, shiftKey: false}
  76. },
  77. {
  78. action: hideDialog,
  79. codes: [27],
  80. keys: 'esc',
  81. label: 'Hide Dialog Window',
  82. modif: {altKey: false, ctrlKey: false, metaKey: false, shiftKey: false}
  83. },
  84. {
  85. action: prevImage,
  86. codes: [37, 38],
  87. keys: '← ↑',
  88. label: 'Previous Image',
  89. modif: {altKey: false, ctrlKey: false, metaKey: false, shiftKey: false}
  90. },
  91. {
  92. action: nextImage,
  93. codes: [39, 40],
  94. keys: '→ ↓',
  95. label: 'Next Image',
  96. modif: {altKey: false, ctrlKey: false, metaKey: false, shiftKey: false}
  97. },
  98. {
  99. action: toggleAutoplay,
  100. codes: [32],
  101. keys: '[space]',
  102. label: 'Start/Stop Autoplay',
  103. modif: {altKey: false, ctrlKey: false, metaKey: false, shiftKey: false}
  104. }
  105. ];
  106. var settings = {
  107. 'autoplay': {
  108. name: 'autoplayDelay',
  109. label: 'Auto Play Delay',
  110. hint: 'in seconds',
  111. type: 'integer',
  112. size: 3,
  113. min: 0,
  114. max: null,
  115. def: 2
  116. },
  117. 'inifiteScrolling': {
  118. name: 'inifiteScrolling',
  119. label: 'Infinite Scrolling',
  120. type: 'boolean',
  121. def: true
  122. },
  123. 'mode': {
  124. name: 'galleryMode',
  125. label: 'Gallery Mode',
  126. type: 'select',
  127. opts: ['scrolling', 'slideshow'],
  128. def: 'scrolling'
  129. },
  130. 'pagination': {
  131. name: 'imageLimit',
  132. label: 'Pagination Limit',
  133. hint: 'use <b>0</b> to disable',
  134. type: 'integer',
  135. size: 3,
  136. min: 0,
  137. max: null,
  138. def: 0
  139. },
  140. 'preloading': {
  141. name: 'preloadingEnabled',
  142. label: 'Image Preloading',
  143. type: 'boolean',
  144. def: true
  145. },
  146. 'theme': {
  147. name: 'theme',
  148. label: 'Gallery Theme',
  149. type: 'select',
  150. opts: ['default', 'classic', 'green', 'blue'],
  151. def: 'default'
  152. },
  153. 'thumbnails': {
  154. name: 'showThumbs',
  155. label: 'Show Thumbnails',
  156. type: 'boolean',
  157. def: true
  158. },
  159. 'thumbnailsSize': {
  160. name: 'thumbnailsSize',
  161. label: 'Thumbnails Size',
  162. type: 'select',
  163. opts: ['small', 'medium', 'large'],
  164. def: 'medium'
  165. }
  166. };
  167.  
  168. // objects for features that need multiple settings and calculated properties
  169. var autoplay = {
  170. active: false,
  171. count: parseInt(GM_getValue(settings.autoplay.name, settings.autoplay.def), 10),
  172. delay: parseInt(GM_getValue(settings.autoplay.name, settings.autoplay.def), 10),
  173. paused: false,
  174. timer: undefined
  175. };
  176. var pagination = {
  177. append: GM_getValue(settings.inifiteScrolling.name, settings.inifiteScrolling.def),
  178. active: false,
  179. limit: parseInt(GM_getValue(settings.pagination.name, settings.pagination.def), 10),
  180. page: parseInt(getHashParam('page'), 10) || 1
  181. };
  182. var preloading = {
  183. active: GM_getValue(settings.preloading.name, settings.preloading.def),
  184. done: false,
  185. pos: activeImage
  186. };
  187.  
  188.  
  189.  
  190. /* ===== Core Functions =====
  191. Where the magic happens...
  192. */
  193.  
  194. /**
  195. * Crawls the normal gallery page and finds all thumbnail images
  196. * @return Array locations of all thumbnail images
  197. */
  198. function findImages() {
  199. var imgs = document.getElementById('gallery').getElementsByTagName('img');
  200. var thumbRegex = /(.*\/images\/thumb\/.*)\/(.*)$/i;
  201.  
  202. var count = 0;
  203. var image;
  204. var ret = [];
  205. for (var i = 0; i < imgs.length; i++) {
  206. if (thumbRegex.test(imgs[i].src)) {
  207. if (imgs[i].src.indexOf("?") > 0) {
  208. var isrc = imgs[i].src.substring(0, imgs[i].src.indexOf("?"));
  209. }
  210. image = {
  211. id: imgs[i].src.split('/').pop().split('.')[0],
  212. pos: count++,
  213. thumb: imgs[i].src,
  214. full: isrc.replace('thumb', 'full').replace("https", "http").replace("cdn.imagefap.com", "109.201.130.54")
  215. };
  216. ret.push(image);
  217. }
  218. }
  219.  
  220. totalImages = ret.length;
  221. return ret;
  222. }
  223.  
  224. /**
  225. * Sets the global variables needed for pagination in other functions
  226. */
  227. function initPagination() {
  228. initSetting('pagination');
  229.  
  230. // reset pagination object properties to default
  231. pagination = {
  232. append: settings.inifiteScrolling.value,
  233. active: (settings.mode.value === 'slideshow'),
  234. limit: parseInt(settings.pagination.value, 10),
  235. page: parseInt(getHashParam('page'), 10) || 1
  236. };
  237.  
  238. if ((pagination.limit <= 0) || (settings.mode.value === 'slideshow')) {
  239. // in slideshow mode pagination is handled as if it is disabled
  240. pagination.active = false;
  241. pagination.limit = totalImages;
  242. pagination.page = 1;
  243. } else {
  244. pagination.active = true;
  245. if (!pagination.page || (pagination.page < 1))
  246. pagination.page = 1;
  247. }
  248.  
  249. // ensure the user is on the correct page
  250. var page = findImagePage();
  251. if (page !== pagination.page) {
  252. setHashParam('page', page);
  253. pagination.page = page;
  254. }
  255. }
  256.  
  257. /**
  258. * Finds the page number that the active image should be on
  259. * @param Int (Optional) The number of the image to find (default: value of activeImage internal variable)
  260. * @return Int The page number containing the active image
  261. */
  262. function findImagePage(pos) {
  263. if ((typeof activeImage === 'undefined') || !activeImage || (activeImage <= 0))
  264. return 1;
  265.  
  266. return parseInt(((activeImage / pagination.limit) + 1), 10);
  267. }
  268.  
  269. /**
  270. * Returns the images that will be used on the current page
  271. * @param Array Objects representing all images from the original gallery
  272. * @return Array Multi-dimensional array of objects representing all images on each page
  273. */
  274. function paginateImages(imgs) {
  275. // if images have been paginated previously, they must first be un-paginated
  276. if (typeof imgs[0] === 'object' && typeof imgs[0][0] === 'object')
  277. imgs = resetImages(imgs);
  278.  
  279. var page = 0;
  280. var ret = [];
  281. for (var i = 0; i < imgs.length; i++) {
  282. if (typeof ret[page] === 'undefined')
  283. ret[page] = [];
  284. ret[page].push(imgs[i]);
  285.  
  286. if (((i + 1) % pagination.limit) === 0)
  287. page++;
  288. }
  289. return ret;
  290. }
  291.  
  292. /** Flattens a paginated multi-dimensional array of images
  293. * @param Array Multi-dimensional array of objects representing all images on multiple page
  294. * @return Array Multi-dimensional array of objects representing all images on one page
  295. */
  296. function resetImages(imgs) {
  297. var ret = [];
  298. for (var i = 0; i < imgs.length; i++) {
  299. for (var j = 0; j < imgs[i].length; j++) {
  300. ret.push(imgs[i][j]);
  301. }
  302. }
  303. // if the supplied array was only 1-dimensional, then the new array will be empty
  304. if (ret.length === 0)
  305. ret = imgs;
  306. return ret;
  307. }
  308.  
  309. /**
  310. * Loads the next "page" of images in Infinite Scrolling mode
  311. * Updates the position text and the pagination links
  312. */
  313. function loadNextPage() {
  314. if (pagination.page < images.length) {
  315. pagination.page++;
  316. showNotification('Loading images from page ' + pagination.page);
  317.  
  318. updatePosition(undefined, (pagination.limit * pagination.page), undefined, undefined);
  319. updatePagination(pagination.page);
  320.  
  321. populateScrollingGallery(images[(pagination.page - 1)], false);
  322. populateThumbnails(images[(pagination.page - 1)], false);
  323.  
  324. setHashParam('page', pagination.page);
  325. } else {
  326. var loader = document.getElementById('loader');
  327. if (loader)
  328. loader.parentNode.removeChild(loader);
  329. }
  330. }
  331.  
  332. /**
  333. * Generates HTML for the help dialog
  334. * @return String HTML to be placed in the dialog
  335. */
  336. function getAbout() {
  337. var about = '';
  338. about += '<p>' + GM_info.script.name + ' v' + GM_info.script.version + '. Automatic script updates are ' + ((GM_info.scriptWillUpdate) ? 'enabled' : 'disabled') + '. </p>';
  339. about += '<p>' + GM_info.script.description + '</p>';
  340.  
  341. return about;
  342. }
  343.  
  344. /**
  345. * Generates HTML for the help dialog
  346. * @return String HTML to be placed in the dialog
  347. */
  348. function getHelp() {
  349. var help = '';
  350. help += '<table>';
  351. help += '<tr><th></th><th>Hotkeys</th></tr>';
  352. for (var h in hotkeys)
  353. help += '<tr><td class="key"><b>' + hotkeys[h].keys + '</b></td><td class="command">' + hotkeys[h].label + '</td></tr>';
  354.  
  355. help += '</table>';
  356.  
  357. return help;
  358. }
  359.  
  360. /**
  361. * Generates the DOM objects needed for the thumbnail images
  362. * @param Array The objects of all images to be displayed
  363. * @param Bool (Optional) If the existing thumbnails should be removed (default: false)
  364. */
  365. function populateThumbnails(imgs, reset) {
  366. reset = (typeof reset === "undefined") ? false : reset;
  367.  
  368. var thumbs = document.getElementById('thumbnails');
  369. if (!thumbs)
  370. return false;
  371.  
  372. if (reset)
  373. thumbs.innerHTML = '';
  374. thumbs.className = settings.thumbnailsSize.value;
  375.  
  376. var img, link;
  377. for (var i = 0; i < imgs.length; i++) {
  378. img = document.createElement('img');
  379. img.src = imgs[i].thumb;
  380.  
  381. link = document.createElement('a');
  382. // link.addEventListener('click', clickThumbnail);
  383. link.className = 'thumbnail';
  384. link.id = 'thumb_' + imgs[i].pos;
  385. link.rel = imgs[i].pos;
  386. link.href = imgs[i].full;
  387. link.appendChild(img);
  388.  
  389. thumbs.appendChild(link);
  390. }
  391. }
  392.  
  393. /**
  394. * Generates the DOM objects needed for the scrolling mode
  395. * @param Array The objects of all images to be displayed
  396. * @param Bool (Optional) If the existing gallery images should be removed (default: false)
  397. */
  398. function populateScrollingGallery(imgs, reset) {
  399. reset = (typeof reset === "undefined") ? false : reset;
  400.  
  401. var gallery = document.getElementById('gallery');
  402. if (!gallery)
  403. return false;
  404.  
  405. if (reset)
  406. gallery.innerHTML = '';
  407.  
  408. var container, img, link, spinner;
  409. for (var i = 0; i < imgs.length; i++) {
  410. img = document.createElement('a');
  411. img.text = 'image '+imgs[i].pos;
  412. img.rel = imgs[i].pos;
  413. img.href = imgs[i].full;
  414.  
  415. spinner = document.createElement('span');
  416. spinner.className = 'spinner';
  417.  
  418. link = document.createElement('a');
  419. link.className = 'image';
  420. link.href = imgs[i].full;
  421. link.id = 'full_' + (((pagination.page - 1) * pagination.limit) + i);
  422.  
  423. link.appendChild(img);
  424. // link.appendChild(spinner);
  425.  
  426. container = document.createElement('p');
  427. container.appendChild(link);
  428.  
  429. gallery.appendChild(container);
  430. }
  431.  
  432. if (pagination.append && (imgs.length < totalImages)) {
  433. var loader = document.getElementById('loader');
  434. if (!loader) {
  435. loader = document.createElement('a');
  436. loader.id = 'loader'
  437. loader.innerHTML = 'Load Next Page of Images';
  438. loader.addEventListener('click', loadNextPage);
  439. }
  440. gallery.appendChild(loader);
  441. }
  442. }
  443.  
  444. /**
  445. * Generates the DOM objects needed for the slideshow mode
  446. * @param Object The object representing the active image
  447. */
  448. function buildSlideshowGallery(active) {
  449. var gallery = document.getElementById('gallery');
  450. if (!gallery)
  451. return false;
  452.  
  453. gallery.innerHTML = '';
  454.  
  455. var prev = document.createElement('a');
  456. prev.addEventListener('click', prevImage);
  457. prev.id = 'prev';
  458. prev.className = 'nav';
  459. prev.innerHTML = '<span class="arrow"><</span>';
  460.  
  461. var next = document.createElement('a');
  462. next.addEventListener('click', nextImage);
  463. next.id = 'next';
  464. next.className = 'nav';
  465. next.innerHTML = '<span class="arrow">></span>';
  466.  
  467. var img = document.createElement('img');
  468. img.alt = '';
  469. img.id = 'slideshowImage';
  470. img.src = active.full;
  471.  
  472. var spinner = document.createElement('span');
  473. spinner.className = 'spinner';
  474.  
  475. var link = document.createElement('a');
  476. link.className = 'image';
  477. link.href = active.full;
  478. link.id = 'slideshowLink';
  479.  
  480. link.appendChild(img);
  481. link.appendChild(spinner);
  482.  
  483. gallery.appendChild(link);
  484. gallery.appendChild(prev);
  485. gallery.appendChild(next);
  486.  
  487. // resize the slideshow area
  488. resizeSlideshowGallery();
  489. }
  490.  
  491. /**
  492. * Resizes the DOM object containing the slideshow image to accomodate non-fixed header and footer sizes
  493. */
  494. function resizeSlideshowGallery() {
  495. var content = document.getElementById('content');
  496. if (!content)
  497. return false;
  498.  
  499. // header
  500. var header = document.getElementById('header');
  501. content.style.top = (header) ? header.offsetHeight + 'px' : '';
  502.  
  503. // footer
  504. var footer = document.getElementById('footer');
  505. content.style.bottom = (footer) ? footer.offsetHeight + 'px' : '';
  506. }
  507.  
  508. /**
  509. * Generates the DOM objects for the header of rebuilt pages
  510. */
  511. function buildHeader() {
  512. var header = document.getElementById('header');
  513. if (!header)
  514. return false;
  515.  
  516. header.innerHTML = '';
  517.  
  518. // logo
  519. var logo = document.createElement('a');
  520. logo.href = window.location.protocol + '//' + window.location.host;
  521. logo.id = 'logo';
  522. logo.innerHTML = '<span class="image">Image</span><span class="fap">Fap</span>';
  523. header.appendChild(logo);
  524.  
  525. // heading
  526. var heading = document.createElement('h2');
  527. heading.id = 'heading';
  528. heading.innerHTML = '"<span class="title">' + stripslashes(title) + '</span>"';
  529. if (author.name && author.url)
  530. heading.innerHTML += ' <small>by</small> <a href="' + author.url + '">' + unescape(stripslashes(author.name)) + '</a>';
  531. header.appendChild(heading);
  532.  
  533. // description
  534. if (desc) {
  535. var description = document.createElement('p');
  536. description.id = 'description';
  537. description.innerHTML = stripslashes(desc);
  538. header.appendChild(description);
  539.  
  540. // if the description spans multiple lines, left-align the text
  541. if (description.offsetHeight > 16)
  542. description.style.textAlign = 'left';
  543. }
  544.  
  545. // sub-heading
  546. var subheading = document.createElement('p');
  547. header.appendChild(subheading);
  548. // sub-heading > position
  549. var position = document.createElement('span');
  550. position.className = settings.mode.value;
  551. position.id = 'position';
  552. subheading.appendChild(position);
  553. // sub-heading > spacer
  554. var separator = document.createElement('span');
  555. separator.innerHTML = ' | ';
  556. subheading.appendChild(separator);
  557. // sub-heading > "toggle thumbnails" link
  558. var toggle = document.createElement('a');
  559. toggle.addEventListener('click', toggleThumbs);
  560. toggle.innerHTML = 'Toggle Thumbnails';
  561. subheading.appendChild(toggle);
  562. // sub-heading > spacer
  563. var separator = document.createElement('span');
  564. separator.innerHTML = ' | ';
  565. subheading.appendChild(separator);
  566. // sub-heading > "change settings" link
  567. var openSettings = document.createElement('a');
  568. openSettings.addEventListener('click', changeSettings);
  569. openSettings.innerHTML = 'Change Settings';
  570. subheading.appendChild(openSettings);
  571.  
  572. // pagination
  573. if (settings.mode.value === 'scrolling' && pagination.active)
  574. buildPagination('header');
  575.  
  576. // search form
  577. var form = document.createElement('form');
  578. form.id = 'search';
  579. form.method = 'POST';
  580. form.action = window.location.protocol + '//' + window.location.host + '/gallery.php';
  581. header.appendChild(form);
  582. // search form > text input
  583. var search = document.createElement('input');
  584. search.type = 'text';
  585. search.value = 'Enter search term(s)...';
  586. search.name = 'search';
  587. search.addEventListener('focus', function() { if (this.value === 'Enter search term(s)...') this.value = ''; });
  588. search.addEventListener('blur', function() { if (this.value === '') this.value = 'Enter search term(s)...'; });
  589. form.appendChild(search);
  590. // search form > submit button
  591. var submit = document.createElement('input');
  592. submit.type = 'submit';
  593. submit.value = 'Search';
  594. submit.name = 'submit';
  595. form.appendChild(submit);
  596. }
  597.  
  598. /**
  599. * Generates the DOM objects for the footer of rebuilt pages
  600. */
  601. function buildFooter() {
  602. var footer = document.getElementById('footer');
  603. if (!footer)
  604. return false;
  605.  
  606. footer.innerHTML = '';
  607.  
  608. footer.appendChild(addFavLink);
  609.  
  610. if (settings.mode.value === 'scrolling' && pagination.active)
  611. buildPagination('footer');
  612.  
  613. buildInfo();
  614. buildAutoplay();
  615. }
  616.  
  617. /**
  618. * Updates the HTML for the position of the current image(s) within the gallery
  619. * @param Int (Optional) The lower limit image number (default: use existing value from DOM)
  620. * @param Int (Optional) The upper limit image number (default: use existing value from DOM)
  621. * @param Int (Optional) The total image number (default: use existing value from DOM)
  622. * @param Int (Optional) The active image number (default: use existing value from DOM)
  623. */
  624. function updatePosition(lower, upper, total, active) {
  625. var position = document.getElementById('position');
  626. if (!position)
  627. return false;
  628.  
  629. if (position.className !== settings.mode.value) {
  630. position.className = settings.mode.value;
  631. position.innerHTML = '';
  632. }
  633.  
  634. if (settings.mode.value === 'scrolling') {
  635. if (position.innerHTML === undefined || position.innerHTML === '')
  636. position.innerHTML = 'Viewing image(s) <span id="position_lower">' + lower + '</span>-<span id="position_upper">' + upper + '</span> of <span id="position_total">' + total + '</span>';
  637.  
  638. lower = (typeof lower === "undefined") ? parseInt(document.getElementById('position_lower').innerHTML, 10) : lower;
  639. upper = (typeof upper === "undefined") ? parseInt(document.getElementById('position_upper').innerHTML, 10) : upper;
  640. total = (typeof total === "undefined") ? parseInt(document.getElementById('position_total').innerHTML, 10) : total;
  641. if (upper > totalImages)
  642. upper = totalImages;
  643. document.getElementById('position_lower').innerHTML = lower;
  644. document.getElementById('position_upper').innerHTML = upper;
  645. document.getElementById('position_total').innerHTML = total;
  646. } else if (settings.mode.value === 'slideshow') {
  647. if (position.innerHTML === undefined || position.innerHTML === '')
  648. position.innerHTML = 'Viewing image <span id="position_active">' + lower + '</span> of <span id="position_total">' + total + '</span>';
  649.  
  650. active = (typeof active === "undefined") ? parseInt(document.getElementById('position_active').innerHTML, 10) : active;
  651. total = (typeof total === "undefined") ? parseInt(document.getElementById('position_total').innerHTML, 10) : total;
  652. document.getElementById('position_active').innerHTML = active;
  653. document.getElementById('position_total').innerHTML = total;
  654. }
  655. }
  656.  
  657. /**
  658. * Generates the DOM objects for the pagination of rebuilt gallery pages
  659. * @param String The ID of the DOM object of which to insert the pagination controls
  660. */
  661. function buildPagination(location) {
  662. var container = document.getElementById(location);
  663. if (!container)
  664. return false;
  665.  
  666. var pages = Math.ceil(totalImages / pagination.limit);
  667.  
  668. if (pages <= 1)
  669. return false;
  670.  
  671. var wrapper = document.createElement('div');
  672. wrapper.className = 'pagination';
  673.  
  674. // previous page
  675. var prev = document.createElement('a');
  676. prev.innerHTML = '&laquo; Prev';
  677. if (pagination.page > 1) {
  678. prev.addEventListener('click', clickPagination);
  679. prev.rel = (pagination.page - 1);
  680. } else {
  681. prev.className = 'disabled';
  682. }
  683. wrapper.appendChild(prev);
  684.  
  685. // individual pages
  686. var link, lower, upper;
  687. for (var i = 1; i <= pages; i++) {
  688. link = document.createElement('a');
  689. link.rel = i;
  690.  
  691. lower = (pagination.limit * (i - 1) + 1);
  692. upper = (i < pages) ? (pagination.limit * i) : totalImages;
  693. link.innerHTML = (lower === upper) ? lower : lower + '-' + upper;
  694.  
  695. if (i === pagination.page) {
  696. link.className = 'current';
  697. } else {
  698. link.addEventListener('click', clickPagination);
  699. }
  700. wrapper.appendChild(link);
  701. }
  702.  
  703. // next page
  704. var next = document.createElement('a');
  705. next.innerHTML = 'Next &raquo;';
  706. if (pagination.page < pages) {
  707. next.addEventListener('click', clickPagination);
  708. next.rel = (pagination.page + 1);
  709. } else {
  710. next.className = 'disabled';
  711. }
  712. wrapper.appendChild(next);
  713.  
  714. container.appendChild(wrapper);
  715. }
  716.  
  717. /**
  718. * Updates the pagination controls
  719. * @param Int The number of the current page
  720. * @param Bool (Optional) If all pagination controls should be reset (default: false)
  721. */
  722. function updatePagination(page, reset) {
  723. reset = (typeof reset === "undefined") ? false : reset;
  724.  
  725. var containers = document.getElementsByClassName('pagination');
  726. if (containers.length === 0)
  727. return false;
  728.  
  729. var links, rel;
  730. for (var i = 0; i < containers.length; i++) {
  731. links = containers[i].getElementsByTagName('a');
  732.  
  733. // first handle all of the inner links (i.e. the numbered ones)
  734. if (reset) {
  735. // this is for when a page is loaded by itself
  736. // activate the target link and reset all of the other links to default
  737. for (var j = 1; j < (links.length - 1); j++) {
  738. if (j === page) {
  739. links[j].className = 'current';
  740. links[j].removeEventListener('click', clickPagination);
  741. } else {
  742. links[j].className = '';
  743. links[j].addEventListener('click', clickPagination);
  744. }
  745. }
  746. } else {
  747. // this is for when a page is appended
  748. // simply activate the target link
  749. links[page].className = 'current';
  750. links[page].removeEventListener('click', clickPagination);
  751. }
  752.  
  753. // the first link is the "Prev" link, which needs to point to the page BEFORE the current page
  754. var prev = links[0];
  755. if (prev.nextSibling && prev.nextSibling.className === 'current') {
  756. prev.rel = page;
  757. prev.className = 'disabled';
  758. prev.removeEventListener('click', clickPagination);
  759. } else {
  760. prev.rel = (page - 1);
  761. prev.className = trim(links[0].className.replace('disabled', ''));
  762. prev.addEventListener('click', clickPagination);
  763. }
  764.  
  765. // the last link is the "Next" link, which needs to point to the page AFTER the current page
  766. var next = links[(links.length - 1)];
  767. if (next.previousSibling && next.previousSibling.className === 'current') {
  768. next.rel = page;
  769. next.className = 'disabled';
  770. next.removeEventListener('click', clickPagination);
  771. } else {
  772. next.rel = (page + 1);
  773. next.className = trim(next.className.replace('disabled', ''));
  774. next.addEventListener('click', clickPagination);
  775. }
  776. }
  777. }
  778.  
  779. /**
  780. * Generates the DOM objects for the information text at the bottom of the footer
  781. */
  782. function buildInfo() {
  783. var footer = document.getElementById('footer');
  784. if (!footer)
  785. return false;
  786.  
  787. var info = document.createElement('p');
  788. info.id = 'info';
  789.  
  790. // "about" link
  791. var about = document.createElement('a');
  792. about.addEventListener('click', displayAbout);
  793. about.innerHTML = GM_info.script.name + ' v' + GM_info.script.version;
  794. info.appendChild(about);
  795.  
  796. // spacer
  797. var separator = document.createElement('span');
  798. separator.innerHTML = ' | ';
  799. info.appendChild(separator);
  800.  
  801. // "help" link
  802. var help = document.createElement('a');
  803. help.addEventListener('click', displayHelp);
  804. help.innerHTML = 'Help (?)';
  805. info.appendChild(help);
  806.  
  807. // spacer
  808. var separator = document.createElement('span');
  809. separator.innerHTML = ' | ';
  810. info.appendChild(separator);
  811.  
  812. // "settings" link
  813. var openSettings = document.createElement('a');
  814. openSettings.addEventListener('click', changeSettings);
  815. openSettings.innerHTML = 'Settings';
  816. info.appendChild(openSettings);
  817.  
  818. footer.appendChild(info);
  819. }
  820.  
  821. /**
  822. * Generates the DOM objects for the autoplay indicator in the footer
  823. */
  824. function buildAutoplay() {
  825. var footer = document.getElementById('footer');
  826. if (!footer)
  827. return false;
  828.  
  829. var autoplay = document.createElement('div');
  830. autoplay.id = 'autoplay';
  831. if (settings.mode.value === 'scrolling') {
  832. var disabled = document.createElement('span');
  833. disabled.innerHTML = 'Autoplay is only available in slideshow mode';
  834. autoplay.appendChild(disabled);
  835. } else if (settings.mode.value === 'slideshow') {
  836. // autoplay counter
  837. var counter = document.createElement('span');
  838. counter.id = 'counter';
  839. counter.innerHTML = (autoplay.count > 0) ? 'Advancing image in ' + autoplay.count + ' seconds' : 'Autoplay is disabled';
  840. autoplay.appendChild(counter);
  841.  
  842. // spacer
  843. var separator = document.createElement('span');
  844. separator.innerHTML = ' | ';
  845. autoplay.appendChild(separator);
  846.  
  847. // autplay control link
  848. var control = document.createElement('a');
  849. control.addEventListener('click', toggleAutoplay);
  850. control.id = 'control';
  851. control.innerHTML = 'Start Autoplay';
  852. autoplay.appendChild(control);
  853. }
  854.  
  855. footer.appendChild(autoplay);
  856. }
  857.  
  858. /**
  859. * Clears out and re-initializes the DOM with the basic HTML needed for the gallery
  860. */
  861. function initDOM() {
  862. document.removeChild(document.getElementsByTagName('html')[0]);
  863.  
  864. var html = document.createElement('html');
  865. head = document.createElement('head');
  866. body = document.createElement('body');
  867. html.appendChild(head);
  868. html.appendChild(body);
  869. document.appendChild(html);
  870.  
  871. head.innerHTML = '<title>' + stripslashes(title) + '</title>';
  872.  
  873. // build the basic HTML structure to prevent missing elements
  874. body.innerHTML = '<div id="header"></div><div id="content"><div id="gallery"></div></div><div id="footer"></div>'
  875. }
  876.  
  877. /**
  878. * Registers the GreaseMonkey Menu commands
  879. * Must be run after the gallery page is initially built
  880. */
  881. function initMenuCommands() {
  882. GM_registerMenuCommand('[' + GM_info.script.name + '] Help', displayHelp);
  883. GM_registerMenuCommand('[' + GM_info.script.name + '] About', displayAbout);
  884. GM_registerMenuCommand('[' + GM_info.script.name + '] Settings', changeSettings);
  885. }
  886.  
  887. /**
  888. * Rebuilds the actual gallery page piece by piece
  889. */
  890. function rebuildGalleryPage() {
  891. hideDialog();
  892. // re-initialize all settings and feature packages
  893. initSettings();
  894. initAutoplay();
  895. initPagination();
  896. initPreloading();
  897.  
  898. // manually remove existing CSS and apply the chosen theme's CSS
  899. var styles = head.getElementsByTagName('style');
  900. for (var i = 0; i < styles.length; i++) {
  901. head.removeChild(styles[i]);
  902. }
  903. GM_addStyle(getCSS());
  904.  
  905. // paginate the images using current pagination settings
  906. images = paginateImages(images);
  907.  
  908. // header
  909. var header = document.getElementById('header');
  910. if (!header) {
  911. header = document.createElement('div');
  912. header.id = 'header';
  913. body.appendChild(header);
  914. }
  915. buildHeader();
  916.  
  917. // thumbnails
  918. var thumbs = document.getElementById('thumbnails');
  919. if (!thumbs) {
  920. thumbs = document.createElement('div');
  921. thumbs.id = 'thumbnails';
  922. header.appendChild(thumbs);
  923. }
  924.  
  925. // content (gallery wrapper)
  926. var content = document.getElementById('content');
  927. if (!content) {
  928. content = document.createElement('div');
  929. content.id = 'content';
  930. body.appendChild(content);
  931. }
  932.  
  933. // main gallery
  934. var gallery = document.getElementById('gallery');
  935. if (!gallery) {
  936. gallery = document.createElement('div');
  937. gallery.id = 'gallery';
  938. content.appendChild(gallery);
  939. }
  940.  
  941. // footer
  942. var footer = document.getElementById('footer');
  943. if (!footer) {
  944. footer = document.createElement('div');
  945. footer.id = 'footer';
  946. body.appendChild(footer);
  947. }
  948. buildFooter();
  949.  
  950. // populate the thumbnails
  951. if (settings.thumbnails.value === false)
  952. thumbs.style.display = 'none';
  953. if (settings.mode.value === 'slideshow')
  954. thumbs.addEventListener('DOMMouseScroll', scrollThumbs, false);
  955. populateThumbnails(images[(pagination.page - 1)], true);
  956.  
  957. // populate the gallery
  958. /*
  959. if (settings.mode.value === 'scrolling') {
  960. gallery.style.marginBottom = (footer.offsetHeight + 10) + 'px';
  961. body.className = 'scrolling';
  962. var lower = ((pagination.limit * (pagination.page-1)) + 1);
  963. var upper = (pagination.limit * pagination.page);
  964. updatePosition(lower, upper, totalImages, undefined);
  965. populateScrollingGallery(images[(pagination.page - 1)], true);
  966. } else if (settings.mode.value === 'slideshow') {
  967. body.className = 'slideshow';
  968. updatePosition(undefined, undefined, totalImages, activeImage);
  969. buildSlideshowGallery(images[(pagination.page - 1)][activeImage]);
  970. refreshNavigation();
  971. }
  972. */
  973.  
  974. // remove the page hash for slideshow mode
  975. if (settings.mode.value === 'slideshow')
  976. unsetHashParam('page');
  977.  
  978. // show the active image, unless it is the first image of a scrolling gallery
  979. if ((settings.mode.value === 'slideshow') || (activeImage > 0))
  980. showImage();
  981.  
  982. // start preloading images if preloading is enabled
  983. if ((settings.mode.value === 'slideshow') && preloading.active)
  984. preloadImage();
  985. }
  986.  
  987. /**
  988. * main function; executes functionality based on page (via URL)
  989. * Redirects to the one-page version of galleries (if not already in one-page mode)
  990. */
  991. function init() {
  992. // prevent the initialization function from running multiple times
  993. if (loaded) {
  994. return false;
  995. } else {
  996. loaded = true;
  997. }
  998.  
  999. var loc = window.location.href;
  1000. if ((loc.indexOf('/gallery/') !== -1) || (loc.indexOf('/pictures/') !== -1)) {
  1001. // this is a gallery page; make sure it is in "One Page" mode and then go to work
  1002. if (loc.indexOf('view') === -1) {
  1003. window.location.href += ((loc.indexOf('?') === -1) ? '?' : '&') + 'view=2';
  1004. } else {
  1005. // populate the global variables from the original gallery page
  1006. title = document.title;
  1007. if (title)
  1008. title = trim(title.replace('Porn pics of ', '').replace(' (Page 1)', ''));
  1009.  
  1010. var links = document.getElementsByTagName('a');
  1011. if (links) {
  1012. var i = 0;
  1013. for (var i = 0; i < links.length; i++) {
  1014. if (links[i].href.indexOf('profile.php?') !== -1) {
  1015. author.name = links[i].href.split('=')[1];
  1016. author.url = links[i].href;
  1017. break;
  1018. }
  1019. }
  1020. }
  1021.  
  1022. desc = document.getElementById('cnt_description');
  1023. if (desc)
  1024. desc = trim(desc.textContent);
  1025.  
  1026. addFavLink = document.getElementById('favorites_container');
  1027.  
  1028. // FINALLY! grab the images, build the gallery, enable the hotkeys, and listen for changes to settings
  1029. images = findImages();
  1030. initDOM();
  1031. rebuildGalleryPage();
  1032. initMenuCommands();
  1033. checkSettings(); // must run after the gallery page is built (otherwise the notification gets wiped out)
  1034. document.addEventListener('keydown', onKeyDown, false);
  1035. window.addEventListener('focus', onWindowFocus, false);
  1036. window.addEventListener('scroll', onWindowScroll, false);
  1037. window.addEventListener('mozfullscreenchange', onFullScreenChange, false);
  1038. window.addEventListener('webkitfullscreenchange', onFullScreenChange, false);
  1039. }
  1040. } else {
  1041. // this might be a page with links to galleries; change all of the links to galleries to "One Page" mode
  1042. var links = document.getElementsByTagName('a');
  1043. if (links) {
  1044. for (var i = 0; i < links.length; i++) {
  1045. if ((links[i].href.indexOf('gallery') !== -1) || (links[i].href.indexOf('pictures') !== -1)) {
  1046. links[i].href += ((links[i].href.indexOf('?') === -1) ? '?' : '&') + 'view=2';
  1047. }
  1048. }
  1049. }
  1050. }
  1051. }
  1052.  
  1053. /**
  1054. * Toggles visibility of the navigational arrows by adding/removing a "disabled" class
  1055. */
  1056. function refreshNavigation() {
  1057. var nav = document.getElementsByClassName('nav');
  1058. for (var i = 0; i < nav.length; i++) {
  1059. nav[i].className = trim(nav[i].className.replace('disabled',''));
  1060. }
  1061.  
  1062. if (activeImage === 0) {
  1063. var prev = document.getElementById('prev');
  1064. if (prev)
  1065. prev.className += ' disabled';
  1066. } else if (activeImage === (pagination.limit - 1)) {
  1067. var next = document.getElementById('next');
  1068. if (next)
  1069. next.className += ' disabled';
  1070. }
  1071. }
  1072.  
  1073. /**
  1074. * Handles the click event for the pagination links
  1075. * @param Event The click event
  1076. */
  1077. function clickPagination(evt) {
  1078. if (this.rel) {
  1079. var page = parseInt(this.rel, 10);
  1080. activeImage = (((page - 1) * pagination.limit) + 1);
  1081. unsetHashParam('image');
  1082. updatePagination(page, true);
  1083. goToPage(page);
  1084. }
  1085. }
  1086.  
  1087. /**
  1088. * Sets the values needed to change pages and rebuilds the gallery for the specified page
  1089. * @param Int The number of the page to display
  1090. */
  1091. function goToPage(page) {
  1092. pagination.page = page;
  1093.  
  1094. var lower = ((pagination.limit * (pagination.page-1)) + 1);
  1095. var upper = (pagination.limit * pagination.page);
  1096.  
  1097. setHashParam('page', page);
  1098. setHashParam('image', lower);
  1099.  
  1100. updatePosition(lower, upper, totalImages, undefined);
  1101.  
  1102. //populateScrollingGallery(images[(page - 1)], true);
  1103. populateThumbnails(images[(page - 1)], true);
  1104.  
  1105. window.scrollTo(0, 0);
  1106. }
  1107.  
  1108. /**
  1109. * Captures mouse scrolling on the thumbnails and scrolls the images horizontally
  1110. * @param Event mouse wheel scroll event
  1111. */
  1112. function scrollThumbs(evt){
  1113. if (!evt)
  1114. evt = this;
  1115. evt.preventDefault(); // prevent vertical scrolling on the page
  1116.  
  1117. var delta = (evt.detail) ? evt.detail : 0;
  1118. window.document.getElementById('thumbnails').scrollLeft += (delta * 10);
  1119.  
  1120. evt.returnValue = false;
  1121. }
  1122.  
  1123. /**
  1124. * Sets the active image based on the thumbnail image that was clicked
  1125. * Expects to be executed as a click event for a DOM object with a "rel" value
  1126. * @param Event The click event
  1127. */
  1128. function clickThumbnail(evt) {
  1129. if (this.rel)
  1130. activeImage = parseInt(this.rel, 10);
  1131. showImage();
  1132. }
  1133.  
  1134. /**
  1135. * Sets the active image to the next image
  1136. * Ensures the active image is not the last one already
  1137. */
  1138. function nextImage() {
  1139. if (settings.mode.value === 'slideshow' && autoplay.active) {
  1140. autoplay.count = autoplay.delay;
  1141. }
  1142.  
  1143. if (activeImage < ((pagination.page * pagination.limit) - 1)) {
  1144. activeImage++;
  1145. showImage();
  1146. }
  1147. }
  1148.  
  1149. /**
  1150. * Sets the active image to the previous image
  1151. * Ensures the active image is not the first one already
  1152. */
  1153. function prevImage() {
  1154. if (settings.mode.value === 'slideshow' && autoplay.active) {
  1155. stopAutoplay();
  1156. }
  1157.  
  1158. if (activeImage > ((pagination.page - 1) * pagination.limit)) {
  1159. activeImage--;
  1160. showImage();
  1161. }
  1162. }
  1163.  
  1164. /**
  1165. * Sets the internal activeImage pointer and sets the image hash parameter
  1166. * Activates the correct thumbnail for the active image
  1167. * @param Int (Optional) The number of the active image (default: value of activeImage internal variable)
  1168. */
  1169. function setActiveImage(pos) {
  1170. pos = (typeof pos === "undefined") ? activeImage : pos;
  1171.  
  1172. setHashParam('page', findImagePage());
  1173. setHashParam('image', (pos + 1));
  1174. showActiveThumb(pos);
  1175. }
  1176.  
  1177. /**
  1178. * Highlights the thumbnail corresponding to the current image
  1179. * and scrolls it into view in slideshow mode
  1180. * @param Int (Optional) The number of the active image (default: value of activeImage internal variable)
  1181. */
  1182. function showActiveThumb(pos) {
  1183. pos = (typeof pos === "undefined") ? activeImage : pos;
  1184.  
  1185. var thumbs = document.getElementsByClassName('thumbnail');
  1186. for (var i = 0; i < thumbs.length; i++) {
  1187. thumbs[i].className = trim(thumbs[i].className.replace('active',''));
  1188. }
  1189.  
  1190. var thumb = document.getElementById('thumb_' + pos);
  1191. if (thumb) {
  1192. thumb.className += ' active';
  1193. if (settings.mode.value === 'slideshow')
  1194. thumb.scrollIntoView();
  1195. }
  1196. }
  1197.  
  1198. /**
  1199. * Displays/navigates to the "active" image
  1200. * In scrolling mode, this simply scrolls the page up/down to the active image,
  1201. * but in slideshow mode, this shows the active image and hides the others
  1202. * @param Int (Optional) The number of the active image (default: value of activeImage internal variable)
  1203. */
  1204. function showImage(pos) {
  1205. pos = (typeof pos === "undefined") ? activeImage : pos;
  1206.  
  1207. setActiveImage(pos);
  1208.  
  1209. if (settings.mode.value === 'scrolling') {
  1210. var target = document.getElementById('full_' + pos);
  1211. if (target)
  1212. target.scrollIntoView();
  1213. } else if (settings.mode.value === 'slideshow') {
  1214. var link = document.getElementById('slideshowLink');
  1215. var img = document.getElementById('slideshowImage');
  1216.  
  1217. if (link && img) {
  1218. showNotification("Loading image " + (pos + 1), 1000);
  1219. // first blank out the current image and link target from the previous image
  1220. // then use a slight delay to set the next image and link target;
  1221. // this causes the loading animation to be played while the image is loaded;
  1222. // if the delay is removed, the previous image will remain visible until the new image is loaded
  1223. // without any indication that the image has changed and the next image is loading
  1224. img.src = link.href = '';
  1225. setTimeout(function() { img.src = link.href = images[pagination.page-1][pos].full; }, 500);
  1226.  
  1227. // always remove the autoplay function from load, and then re-add again if autoplay is still enabled
  1228. img.removeEventListener('load', startAutoplay);
  1229. if (autoplay.active && !autoplay.paused) {
  1230. img.addEventListener('load', startAutoplay);
  1231. }
  1232.  
  1233. updatePosition(undefined, undefined, totalImages, (pos + 1));
  1234. refreshNavigation();
  1235.  
  1236. if (preloading.active && !preloading.done && (preloading.pos < activeImage))
  1237. preloading.pos = activeImage;
  1238. }
  1239. }
  1240. }
  1241.  
  1242. /**
  1243. * Event handler for keypresses
  1244. * Used to handle hotkeys
  1245. * @param Event The keypress event
  1246. */
  1247. function onKeyDown(evt) {
  1248. if (!evt)
  1249. evt = this;
  1250.  
  1251. if ((evt.target.nodeName === 'INPUT') || (evt.target.nodeName === 'SELECT') || (evt.target.nodeName === 'TEXTAREA'))
  1252. return false;
  1253.  
  1254. var correct = true,
  1255. hotkey;
  1256. for (var h in hotkeys) {
  1257. hotkey = hotkeys[h];
  1258. for (var c in hotkey.codes) {
  1259. if (evt.keyCode === hotkey.codes[c]) {
  1260. for (var m in hotkey.modif) {
  1261. correct = (evt[m] === hotkey.modif[m]) ? correct : false;
  1262. }
  1263. if (correct) {
  1264. evt.preventDefault();
  1265. return (typeof hotkey.action === 'function') ? hotkey.action.call() : eval(hotkey.action);
  1266. }
  1267. }
  1268. }
  1269. }
  1270. }
  1271.  
  1272. /**
  1273. * Event handler for window scroll
  1274. * Used to update the active image when manually scrolling in the scrolling gallery
  1275. * and to determine if the next page of images should be loaded
  1276. * @param Event The scroll event
  1277. */
  1278. function onWindowScroll(evt) {
  1279. if (settings.mode.value === 'scrolling') {
  1280. var imgs = document.getElementById('gallery').getElementsByTagName('img');
  1281. var target = 0;
  1282.  
  1283. // loop backwards through the images until the currently visible image is found
  1284. for (var i = (imgs.length - 1); i >= 0; i--) {
  1285. var current = imgs[i].parentNode.offsetTop;
  1286.  
  1287. if (document.body.scrollTop >= current) {
  1288. target = parseInt(imgs[i].rel, 10);
  1289. break;
  1290. }
  1291. }
  1292.  
  1293. // only update the active image if it changed
  1294. if (target !== activeImage) {
  1295. activeImage = target;
  1296. setActiveImage();
  1297. }
  1298.  
  1299. if (pagination.append) {
  1300. var last = imgs[(imgs.length - 1)];
  1301. if ((last.parentNode.offsetTop - window.innerHeight) <= window.pageYOffset) {
  1302. loadNextPage();
  1303. }
  1304. }
  1305. }
  1306. }
  1307.  
  1308. /**
  1309. * Event handler for window focus
  1310. * Used to monitor setting changes and refresh the gallery when needed
  1311. * @param Event The focus event
  1312. */
  1313. function onWindowFocus(evt) {
  1314. var prevMode = settings.mode.value;
  1315. var prevPagination = settings.pagination.value;
  1316. initSettings();
  1317.  
  1318. var refresh = false;
  1319.  
  1320. var thumbs = document.getElementById('thumbnails');
  1321. if (thumbs) {
  1322. // thumbnails can be toggled without rebuilding the entire gallery page
  1323. thumbs.className = settings.thumbnailsSize.value;
  1324. thumbs.style.display = (settings.thumbnails.value === true) ? 'block' : 'none';
  1325. if (settings.mode.value === 'slideshow')
  1326. resizeSlideshowGallery();
  1327. }
  1328.  
  1329. if (prevMode !== settings.mode.value) {
  1330. // current gallery mode does not match the stored preferences
  1331. refresh = true;
  1332. }
  1333.  
  1334. if (settings.mode.value === 'scrolling') {
  1335. if (prevPagination !== settings.pagination.value) {
  1336. // current gallery pagination does not match the stored preferences
  1337. refresh = true;
  1338. }
  1339. }
  1340.  
  1341. if (refresh)
  1342. rebuildGalleryPage();
  1343. }
  1344.  
  1345. /**
  1346. * Displays the about dialog
  1347. */
  1348. function displayAbout() {
  1349. showDialog(getAbout(), 'About');
  1350. }
  1351.  
  1352. /**
  1353. * Displays the help dialog
  1354. */
  1355. function displayHelp() {
  1356. showDialog(getHelp(), 'Help');
  1357. }
  1358.  
  1359. /**
  1360. * Re-initialize the autoplay settings
  1361. */
  1362. function initAutoplay() {
  1363. if (autoplay.timer)
  1364. window.clearTimeout(autoplay.timer);
  1365.  
  1366. initSetting('autoplay');
  1367.  
  1368. // reset autoplay object properties to default
  1369. autoplay = {
  1370. active: false,
  1371. count: parseInt(settings.autoplay.value, 10),
  1372. delay: parseInt(settings.autoplay.value, 10),
  1373. paused: false,
  1374. timer: undefined
  1375. };
  1376. }
  1377.  
  1378. /**
  1379. * Starts the autoplay used timer for advancing to the next image
  1380. * If the delay is not set correctly, the user is prompted to set it
  1381. */
  1382. function startAutoplay() {
  1383. if (!autoplay.active)
  1384. return false;
  1385.  
  1386. if (autoplay.delay > 1000) {
  1387. // the delay is likely in milliseconds, so convert it to seconds and save
  1388. autoplay.delay /= 1000;
  1389. GM_setValue(settings.autoplay.name, autoplay.delay);
  1390. initAutoplay();
  1391. }
  1392.  
  1393. if (autoplay.delay < 0) {
  1394. // the delay is invalid; inform the user
  1395. var buttons = {0: {text: 'Change Settings', action: changeSettings}};
  1396. showDialog('<p>The current value for the ' + settings.autoplay.label + ' is not valid.</p>', 'Invalid ' + settings.autoplay.label, buttons);
  1397. } else {
  1398. autoplay.count = autoplay.delay;
  1399. if (activeImage < totalImages) {
  1400. autoplayTimer();
  1401. } else {
  1402. stopAutoplay();
  1403. }
  1404. }
  1405. }
  1406.  
  1407. /**
  1408. * Stops the autoplay timer used for advancing to the next image
  1409. */
  1410. function stopAutoplay() {
  1411. window.clearTimeout(autoplay.timer);
  1412. autoplay.active = false;
  1413. autoplay.count = autoplay.delay;
  1414.  
  1415. var counter = document.getElementById('counter');
  1416. if (counter)
  1417. counter.innerHTML = 'Autoplay is disabled';
  1418.  
  1419. var control = document.getElementById('control');
  1420. if (control)
  1421. control.innerHTML = 'Start Autoplay';
  1422. }
  1423.  
  1424. /**
  1425. * Pauses the autoplay timer
  1426. */
  1427. function pauseAutoplay() {
  1428. window.clearTimeout(autoplay.timer);
  1429. autoplay.paused = true;
  1430.  
  1431. var counter = document.getElementById('counter');
  1432. if (counter)
  1433. counter.innerHTML = 'Autoplay is paused';
  1434.  
  1435. var control = document.getElementById('control');
  1436. if (control)
  1437. control.innerHTML = 'Resume Autoplay';
  1438. }
  1439.  
  1440. /**
  1441. * Resumes the autoplay timer
  1442. */
  1443. function resumeAutoplay() {
  1444. var counter = document.getElementById('counter');
  1445. if (counter)
  1446. counter.innerHTML = 'Resuming autoplay...';
  1447.  
  1448. var control = document.getElementById('control');
  1449. if (control)
  1450. control.innerHTML = 'Pause Autoplay';
  1451.  
  1452. autoplay.paused = false;
  1453. autoplayTimer();
  1454. }
  1455.  
  1456. /**
  1457. * Starts the counter indicator for advancing to the next image
  1458. */
  1459. function autoplayTimer() {
  1460. window.clearTimeout(autoplay.timer);
  1461.  
  1462. var counter = document.getElementById('counter');
  1463. if (!counter)
  1464. return false;
  1465.  
  1466. if (activeImage < (totalImages - 1)) {
  1467. if (autoplay.count > 0) {
  1468. autoplay.timer = window.setTimeout(autoplayTimer, 1000);
  1469. counter.innerHTML = 'Advancing image in <b>' + autoplay.count + '</b> seconds';
  1470. } else {
  1471. counter.innerHTML = 'Loading image...';
  1472. nextImage();
  1473. }
  1474. autoplay.count--;
  1475. } else {
  1476. counter.innerHTML = 'End of gallery';
  1477. }
  1478. }
  1479.  
  1480. /**
  1481. * Toggles autoplay (start and pause/resume)
  1482. */
  1483. function toggleAutoplay() {
  1484. autoplay.active = !autoplay.active;
  1485. if (autoplay.active) {
  1486. resumeAutoplay();
  1487. } else {
  1488. pauseAutoplay();
  1489. }
  1490.  
  1491. if (fullscreen)
  1492. showAutoplayIndicator();
  1493. }
  1494.  
  1495. /**
  1496. * Displays an indicator when toggling autoplay
  1497. */
  1498. function showAutoplayIndicator() {
  1499. var gallery = document.getElementById('gallery');
  1500. if (!gallery)
  1501. return false;
  1502.  
  1503. var indicator = document.getElementById('indicator');
  1504. if (indicator)
  1505. hideAutoplayIndicator(0);
  1506.  
  1507. indicator = document.createElement('div');
  1508. indicator.id = 'indicator';
  1509. indicator.style.opacity = 1;
  1510. gallery.appendChild(indicator);
  1511.  
  1512. if (autoplay.active) {
  1513. indicator.innerHTML = '<span class="symbol play">&#9658;</span>';
  1514. } else {
  1515. indicator.innerHTML = '<span class="symbol pause">||</span>';
  1516. }
  1517. setTimeout(function() { hideAutoplayIndicator(100); }, 1000);
  1518. }
  1519.  
  1520. /**
  1521. * Fades the autoplay indicator
  1522. */
  1523. function hideAutoplayIndicator(duration) {
  1524. duration = (typeof duration === "undefined") ? 100 : duration;
  1525.  
  1526. var indicator = document.getElementById('indicator');
  1527. if (!indicator)
  1528. return false;
  1529.  
  1530. var timer = setInterval(function() {
  1531. if (indicator === null || indicator.parentNode === null) {
  1532. clearInterval(timer);
  1533. } else {
  1534. indicator.style.opacity -= 0.1
  1535. if (indicator.style.opacity <= 0)
  1536. indicator.parentNode.removeChild(indicator);
  1537. }
  1538. }, duration);
  1539. }
  1540.  
  1541. /**
  1542. * Toggles the slideshow mode for gallery pages
  1543. * A dialog is shown after toggling to allow the user to apply the change immediately
  1544. * @param Bool (Optional) If a nofitication should be displayed (default: true)
  1545. */
  1546. function switchGalleryMode(notify) {
  1547. notify = (typeof notify === "undefined") ? true : notify;
  1548.  
  1549. if (settings.mode.value === 'slideshow')
  1550. GM_setValue(settings.mode.name, 'scrolling');
  1551. else if (settings.mode.value === 'scrolling')
  1552. GM_setValue(settings.mode.name, 'slideshow');
  1553. initSetting('mode');
  1554.  
  1555. if (notify) {
  1556. var buttons = {0: {text: 'Apply Change Now', action: rebuildGalleryPage}, 1: {text: 'Close', action: hideDialog}};
  1557. showDialog('<p>Gallery mode has been changed to ' + settings.mode.value + '.</p>', 'Gallery Mode', buttons);
  1558. }
  1559. }
  1560.  
  1561. /**
  1562. * Toggles visibilty on thumbnails and stores the preference
  1563. */
  1564. function toggleThumbs() {
  1565. GM_setValue(settings.thumbnails.name, !GM_getValue(settings.thumbnails.name, settings.thumbnails.def));
  1566. initSetting('thumbnails');
  1567.  
  1568. var visible = settings.thumbnails.value;
  1569.  
  1570. var thumbs = document.getElementById('thumbnails');
  1571. if (thumbs) {
  1572. var thumbsHeight = thumbs.offsetHeight;
  1573. thumbs.style.display = (visible) ? 'block' : 'none';
  1574. showNotification('Thumbnails are now ' + ((visible) ? 'visible' : 'hidden'), 1000);
  1575.  
  1576. if (settings.mode.value === 'slideshow') {
  1577. resizeSlideshowGallery();
  1578. } else if (settings.mode.value === 'scrolling') {
  1579. if (visible) {
  1580. // scroll the window up to the top of the page when thumbnails are visible
  1581. window.scrollTo(0, 0);
  1582. } else {
  1583. // attempt to prevent the page from scrolling too much when thumbnails are hidden
  1584. window.scrollTo(0, (window.pageYOffset - thumbsHeight - 10));
  1585. }
  1586. }
  1587. }
  1588. }
  1589.  
  1590. /**
  1591. * Re-initialize the preloading settings
  1592. */
  1593. function initPreloading() {
  1594. initSetting('preloading');
  1595.  
  1596. // reset autoplay object properties to default
  1597. var preloading = {
  1598. active: settings.preloading.value,
  1599. done: false,
  1600. pos: activeImage
  1601. };
  1602. }
  1603.  
  1604. /**
  1605. * Preloads the next image in slideshow mode
  1606. * Will be called continuously until the last image is loaded
  1607. */
  1608. function preloadImage() {
  1609. if (!preloading.active)
  1610. return false;
  1611.  
  1612. if (preloading.pos < (totalImages - 1)) {
  1613. preloading.pos++;
  1614. showNotification("Preloading image " + (preloading.pos + 1), 1000);
  1615. var preloader = new Image();
  1616. preloader.src = images[pagination.page-1][preloading.pos].full;
  1617. preloader.addEventListener('load', preloadImage);
  1618. } else {
  1619. preloading.done = true;
  1620. }
  1621. }
  1622.  
  1623. /**
  1624. * Toggles full screen view in supported browsers
  1625. * Full screen view is only available in slideshow mode
  1626. */
  1627. function toggleFullScreen() {
  1628. if (settings.mode.value !== 'slideshow')
  1629. return false;
  1630.  
  1631. if (!document.mozFullScreenElement && !document.webkitFullscreenElement) {
  1632. var target = document.getElementById('content');
  1633. if (target.mozRequestFullScreen) {
  1634. target.mozRequestFullScreen();
  1635. } else if (target.webkitRequestFullscreen) {
  1636. target.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  1637. } else {
  1638. showDialog('Sorry, but it seems your browser does not support customized fullscreen HTML.', 'Fullscreen Error');
  1639. }
  1640. } else {
  1641. if (document.mozCancelFullScreen) {
  1642. document.mozCancelFullScreen();
  1643. } else if (document.webkitCancelFullScreen) {
  1644. document.webkitCancelFullScreen();
  1645. }
  1646. }
  1647. }
  1648.  
  1649. /**
  1650. * Event handler for fullscreen enter/exit
  1651. * Used to move the thumbnails container into the c#ontent container in fullscreen mode
  1652. * and back to the #header container when not in fullscreen mode
  1653. * @param Event fullscreenchange event
  1654. */
  1655. function onFullScreenChange(evt) {
  1656. fullscreen = !(document.mozFullScreenElement === null || document.webkitFullscreenElement === null);
  1657. if (fullscreen) {
  1658. document.getElementById('content').insertBefore(document.getElementById('thumbnails'), document.getElementById('gallery'));
  1659. } else {
  1660. document.getElementById('header').appendChild(document.getElementById('thumbnails'));
  1661. }
  1662. resizeSlideshowGallery();
  1663. }
  1664.  
  1665.  
  1666.  
  1667. /* ===== Dialog Functions =====
  1668. Rather than using boring alert() and prompt() boxes, which are finicky in Greasemonkey,
  1669. this script creates a div, styled with CSS, to replicate that functionality.
  1670. */
  1671.  
  1672. /**
  1673. * Generates the DOM elements for the dialog boxes
  1674. */
  1675. function buildDialog() {
  1676. var dialog = document.getElementById('dialogBox');
  1677. if (dialog) {
  1678. resetDialog();
  1679. return;
  1680. }
  1681.  
  1682. dialog = document.createElement('div');
  1683. dialog.id = 'dialogBox';
  1684. dialog.innerHTML = '<h3 id="dialogTitle"></h3><div id="dialogMessage"></div><div id="dialogButtons"></div>';
  1685.  
  1686. var closeButton = document.createElement('a');
  1687. closeButton.addEventListener('click', hideDialog, false);
  1688. closeButton.id = 'dialogClose';
  1689. closeButton.innerHTML = '&#10006;';
  1690. dialog.appendChild(closeButton);
  1691.  
  1692. var dialogContainer = document.createElement('div');
  1693. dialogContainer.addEventListener('click', function(e) { hideDialog(e, true); }, false);
  1694. dialogContainer.id = 'dialogContainer';
  1695. dialogContainer.style.display = 'none';
  1696. dialogContainer.appendChild(dialog);
  1697. body.appendChild(dialogContainer);
  1698. }
  1699.  
  1700. /**
  1701. * Hides the dialog box
  1702. * @param Event The click event
  1703. * @param Bool (Optional) If true, will only hide the dialog if the target of the click event is the dialogContainer
  1704. */
  1705. function hideDialog(e, containerOnly) {
  1706. containerOnly = (typeof containerOnly === "undefined") ? false : containerOnly;
  1707. if (containerOnly && (typeof e !== "undefined") && (e.target.id !== 'dialogContainer'))
  1708. return false;
  1709.  
  1710. var dialogContainer = document.getElementById('dialogContainer');
  1711. if (dialogContainer)
  1712. dialogContainer.style.display = 'none';
  1713. }
  1714.  
  1715. /**
  1716. * Vertically centers the dialog box on the screen
  1717. */
  1718. function positionDialog() {
  1719. var dialogBox = document.getElementById('dialogBox');
  1720. var dialogContainer = document.getElementById('dialogContainer');
  1721.  
  1722. dialogContainer.style.display = 'block';
  1723. var top = ((window.innerHeight / 2) - (dialogBox.offsetHeight / 2) - 20);
  1724. dialogBox.style.top = (top < 0) ? '0' : top + 'px';
  1725.  
  1726. dialogContainer.scrollTop = 0;
  1727. }
  1728.  
  1729. /**
  1730. * Clears out the contents of the dialog box
  1731. */
  1732. function resetDialog() {
  1733. document.getElementById('dialogTitle').innerHTML = '';
  1734. document.getElementById('dialogMessage').innerHTML = '';
  1735. document.getElementById('dialogButtons').innerHTML = '';
  1736. }
  1737.  
  1738. /**
  1739. * Preloads the next image in slideshow mode
  1740. * Will be called continuously until the last image is loaded
  1741. * @param String The HTML content of the dialog box
  1742. * @param String (Optional) A title for the dialog box (always prefixed with '[Script Name]')
  1743. * @param Object (Optional) An object representing the buttons to display and their actions (default: close button)
  1744. */
  1745. function showDialog(content, title, buttons) {
  1746. buttons = (typeof buttons === "undefined") ? {0: {text: 'Close', action: hideDialog}} : buttons;
  1747. title = (typeof title === "undefined") ? '' : title;
  1748.  
  1749. buildDialog();
  1750.  
  1751. var dialogContainer = document.getElementById('dialogContainer');
  1752. var titleContainer = document.getElementById('dialogTitle');
  1753. var messageContainer = document.getElementById('dialogMessage');
  1754. var buttonContainer = document.getElementById('dialogButtons');
  1755.  
  1756. titleContainer.innerHTML = '[<b>' + GM_info.script.name + '</b>] ' + title;
  1757. messageContainer.innerHTML = content;
  1758.  
  1759. var btn;
  1760. for (var button in buttons) {
  1761. btn = document.createElement('button');
  1762. btn.addEventListener('click', buttons[button].action, false);
  1763. btn.innerHTML = buttons[button].text;
  1764. if(button == 0)
  1765. btn.className = 'default';
  1766. buttonContainer.appendChild(btn);
  1767. }
  1768.  
  1769. positionDialog();
  1770.  
  1771. buttonContainer.childNodes[0].focus();
  1772. }
  1773.  
  1774.  
  1775.  
  1776. /* ===== Notication Message Functions =====
  1777. The are notification messages that display in the lower right corner and are
  1778. automatically removed after a short duration without needing user interaction.
  1779. */
  1780.  
  1781. /**
  1782. * Generates and displays a notification message
  1783. * @param String The notification message text
  1784. * @param Int (Optional) The delay (in milliseconds) before the message should be hidden (default: 5000)
  1785. * @param Int (Optional) The duration (in milliseconds) over which the message should fade (default: 100)
  1786. * @return Object The DOM object of the created notification
  1787. */
  1788. function showNotification(text, delay, duration) {
  1789. delay = (typeof delay === "undefined") ? 5000 : delay;
  1790.  
  1791. var notificationContainer = document.getElementById('notificationContainer');
  1792. if (!notificationContainer) {
  1793. notificationContainer = document.createElement('div');
  1794. notificationContainer.id = 'notificationContainer';
  1795. document.getElementById('content').appendChild(notificationContainer);
  1796. }
  1797. notificationContainer.style.bottom = (document.getElementById('footer').offsetHeight + 10) + 'px';
  1798.  
  1799. var notifications = notificationContainer.getElementsByClassName('notification');
  1800.  
  1801. var notification = document.createElement('div');
  1802. notification.className = 'notification';
  1803. notification.id = 'notification' + notifications.length;
  1804. notification.innerHTML = text;
  1805.  
  1806. if (notifications.length > 0) {
  1807. notificationContainer.insertBefore(notification, notifications[0]);
  1808. } else {
  1809. notificationContainer.appendChild(notification);
  1810. }
  1811.  
  1812. if (delay > 0)
  1813. setTimeout(function() { hideNotification(notification, duration); }, delay);
  1814.  
  1815. return notification;
  1816. }
  1817.  
  1818. /**
  1819. * Fades a notification message out and then removes it
  1820. * @param Object The notification message to hide
  1821. * @param Int (Optional) The duration (in milliseconds) over which the message should fade (default: 100)
  1822. */
  1823. function hideNotification(notification, duration) {
  1824. duration = (typeof duration === "undefined") ? 100 : duration;
  1825.  
  1826. if (!notification)
  1827. return false;
  1828.  
  1829. notification.style.opacity = 1;
  1830. var timer = setInterval(function() {
  1831. notification.style.opacity -= 0.1
  1832. if (notification.style.opacity <= 0) {
  1833. notification.parentNode.removeChild(notification);
  1834. clearInterval(timer);
  1835. }
  1836. }, duration);
  1837. }
  1838.  
  1839.  
  1840. /* ===== Setting Functions =====
  1841. Functions used for working with the individual settings in bulk
  1842. */
  1843.  
  1844. /**
  1845. * Saves the values for all settings from the Settings Form Dialog Box
  1846. * Verifies values are valid based on criteria of the individual settings (min, max, etc.)
  1847. */
  1848. function applySettings() {
  1849. var setting, field, value;
  1850. for (s in settings) {
  1851. setting = settings[s];
  1852. if (setting && (typeof setting === 'object')) {
  1853. value = null;
  1854. field = document.getElementById('setting-' + s);
  1855. if (field) {
  1856. switch (setting.type) {
  1857. case 'integer':
  1858. value = parseInt(field.value, 10);
  1859. if (isNaN(value)) {
  1860. var buttons = {0: {text: 'Try Again', action: changeSettings}};
  1861. showDialog('<p>A numeric value must be provided for <b>' + setting.label + '</b>.</p>', 'Error', buttons);
  1862. return false;
  1863. }
  1864. if ((typeof setting.min !== 'undefined') && (setting.min !== null) && (value < setting.min)) {
  1865. var buttons = {0: {text: 'Try Again', action: changeSettings}};
  1866. showDialog('<p>The value provided (<span class="error">' + value + '</span>) for <b>' + setting.label + '</b> must be greater than or equal to <b>' + setting.min + '</b>.</p>', 'Error', buttons);
  1867. return false;
  1868. }
  1869. if ((typeof setting.max !== 'undefined') && (setting.max !== null) && (value > setting.max)) {
  1870. var buttons = {0: {text: 'Try Again', action: changeSettings}};
  1871. showDialog('<p>The value provided for (<span class="error">' + value + '</span>) <b>' + setting.label + '</b> must be less than or equal to <b>' + setting.max + '</b>.</p>', 'Error', buttons);
  1872. return false;
  1873. }
  1874. break;
  1875. case 'select':
  1876. value = field.options[field.selectedIndex].value;
  1877. break;
  1878. case 'boolean':
  1879. value = field.checked;
  1880. break;
  1881. default:
  1882. value = field.value;
  1883. break;
  1884. }
  1885. }
  1886. if (value !== null) {
  1887. settings[s].value = value;
  1888. }
  1889. }
  1890. }
  1891. saveSettings();
  1892. var buttons = {0: {text: 'Apply Changes Now', action: rebuildGalleryPage}, 1: {text: 'Close', action: hideDialog}};
  1893. showDialog('<p>Your changes have been saved successfully!</p>', 'Success', buttons);
  1894. }
  1895.  
  1896. /**
  1897. * Checks if settings have been saved for the current script version.
  1898. * For new installs, a notice is displayed forcing the user to save the settings for the first time;
  1899. * for updates, the user can view the settings or dismiss the notice.
  1900. */
  1901. function checkSettings() {
  1902. var lastSavedVersion = GM_getValue('lastSavedVersion', false);
  1903. if (!lastSavedVersion) {
  1904. var buttons = {0: {text: 'Continue', action: changeSettings}};
  1905. showDialog('<p>Since this is your first time using ' + GM_info.script.name + ', you need to view (and modify) the settings to meet your needs.</p><p>Note that all settings have a default value set already for your convenience; you can simply click the "Save Settings" button on the next dialog box to continue.', 'First Run', buttons);
  1906. } else if (lastSavedVersion !== GM_info.script.version) {
  1907. GM_setValue('lastSavedVersion', GM_info.script.version);
  1908. var buttons = {0: {text: 'Change Settings', action: changeSettings}, 1: {text: 'Close', action: hideDialog}};
  1909. showDialog('<p>The version of this script has changed from ' + lastSavedVersion + ' to ' + GM_info.script.version + '. There may be new settings for you to utilize.', 'Version Change', buttons);
  1910. }
  1911. }
  1912.  
  1913. /**
  1914. * Initializes all settings from saved preferences
  1915. * Uses the default values for settings that have not yet been saved
  1916. */
  1917. function initSettings() {
  1918. for (s in settings) {
  1919. initSetting(s)
  1920. }
  1921. }
  1922.  
  1923. /**
  1924. * Initializes the specified setting from saved preferences
  1925. * Uses the default value for settings that have not yet been saved
  1926. * @param String name (key) of the setting to initialize
  1927. */
  1928. function initSetting(s) {
  1929. if (settings[s] && (typeof settings[s] === 'object')) {
  1930. if (settings[s].name)
  1931. settings[s].value = GM_getValue(settings[s].name, settings[s].def);
  1932.  
  1933. if (settings[s].type === 'integer')
  1934. settings[s].value = parseInt(settings[s].value, 10);
  1935. else if ((settings[s].type === 'select') && (settings[s].opts.indexOf(settings[s].value) === -1))
  1936. settings[s].value = settings[s].def;
  1937. }
  1938. }
  1939.  
  1940. /**
  1941. * Generates the HTML for the Settings Form that will be displayed via dialog box
  1942. */
  1943. function changeSettings() {
  1944. initSettings();
  1945. var setting;
  1946. var html = '<form id="settingsForm">';
  1947. for (s in settings) {
  1948. setting = settings[s];
  1949. if (setting && (typeof setting === 'object')) {
  1950. html += '<fieldset><legend>' + setting.label + '</legend>';
  1951. switch (setting.type) {
  1952. case 'integer':
  1953. case 'text':
  1954. html += '<label for="setting-' + s + '">Enter a value for the ' + setting.label;
  1955. if (setting.hint)
  1956. html += ' (' + setting.hint + ')';
  1957. html += ':<br/><span class="default">Default value: <b>' + setting.def + '</b></span></label>';
  1958. html += '<input type="text" id="setting-' + s + '" name="' + s + '" value="' + setting.value + '" size="' + setting.size + '" maxlength="' + setting.size + '"/>';
  1959. break;
  1960. case 'select':
  1961. html += '<label for="setting-' + s + '">Select a value for the ' + setting.label;
  1962. if (setting.hint)
  1963. html += ' (' + setting.hint + ')';
  1964. html += ':<br/><span class="default">Default value: <b>' + capitalize(setting.def) + '</b></span></label>';
  1965. html += '<select id="setting-' + s + '" name="' + s + '">';
  1966. for (opt in setting.opts) {
  1967. html += '<option value="' + setting.opts[opt] + '"' + ((setting.value === setting.opts[opt]) ? ' selected="selected"' : '') + '>' + capitalize(setting.opts[opt]) + '</option>';
  1968. }
  1969. html += '</select>';
  1970. break;
  1971. case 'boolean':
  1972. html += '<input type="checkbox" id="setting-' + s + '" name="' + s + '" value="true"' + ((setting.value) ? ' checked="checked"' : '') + '/>';
  1973. html += '<label for="setting-' + s + '">Enable ' + setting.label;
  1974. if (setting.hint)
  1975. html += ' (' + setting.hint + ')';
  1976. html += '<br/><span class="default">Default value: <b>' + ((setting.def) ? 'Enabled' : 'Disabled') + '</b></span></label>';
  1977. break;
  1978. }
  1979. html += '</fieldset>';
  1980. }
  1981. }
  1982. showDialog(html, 'Settings', {0: {text: 'Save Settings', action: applySettings}, 1: {text: 'Cancel', action: hideDialog}});
  1983. }
  1984.  
  1985. /**
  1986. * Saves the current value for each setting to local storage
  1987. */
  1988. function saveSettings() {
  1989. var setting;
  1990. for (s in settings) {
  1991. setting = settings[s];
  1992. if (setting && (typeof setting === 'object'))
  1993. GM_setValue(setting.name, setting.value);
  1994. }
  1995. initSettings();
  1996. GM_setValue('lastSavedVersion', GM_info.script.version);
  1997. }
  1998.  
  1999.  
  2000.  
  2001. /* ===== String Functions =====
  2002. Utility functions for manipulating strings
  2003. */
  2004.  
  2005. /**
  2006. * Escapes quotes and double-quotes in a string
  2007. * @param String The string to escape
  2008. * @return String The escaped string
  2009. */
  2010. function addslashes(str) {
  2011. return str.replace(/\\/g,'\\\\').replace(/\'/g,'\\\'').replace(/\"/g,'\\"').replace(/\0/g,'\\0');
  2012. }
  2013.  
  2014. /**
  2015. * Unescapes quotes and double-quotes in a string
  2016. * @param String The escaped string
  2017. * @return String The string to escape
  2018. */
  2019. function stripslashes(str) {
  2020. return str.replace(/\\'/g,'\'').replace(/\\"/g,'"').replace(/\\0/g,'\0').replace(/\\\\/g,'\\');
  2021. }
  2022.  
  2023. /**
  2024. * Removes leading and trailing whitepsace from a string
  2025. * @param String The string to trim
  2026. * @return String The trimmed string
  2027. */
  2028. function trim(str) {
  2029. return str.replace(/^\s+|\s+$/g,'');
  2030. }
  2031.  
  2032. /**
  2033. * Capitalizes the first character of a string
  2034. * @param String The string to capitalize
  2035. * @return String The capitalized string
  2036. */
  2037. function capitalize(str) {
  2038. return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
  2039. }
  2040.  
  2041.  
  2042.  
  2043. /* ===== Hash Parameter Functions =====
  2044. Utility functions for setting and retrieving data from the URL location hash
  2045. */
  2046.  
  2047. /**
  2048. * Returns all key/value pairs stored in the location hash
  2049. * @return Object The location hash parameters indexed by key name
  2050. */
  2051. function getHashParams() {
  2052. var params = window.location.hash.replace('#!','').split('/');
  2053. var ret = [];
  2054. for (var i = 0; i < params.length; i = i + 2) {
  2055. if (params[(i + 1)] && params[(i + 2)])
  2056. ret[params[(i + 1)]] = params[(i + 2)];
  2057. }
  2058. return ret;
  2059. }
  2060.  
  2061. /**
  2062. * Returns the value of the supplied hash key
  2063. * @param String The name of the hash key
  2064. * @return String The value of the hash key
  2065. */
  2066. function getHashParam(key) {
  2067. var params = getHashParams();
  2068. return params[key] || undefined;
  2069. }
  2070.  
  2071. /**
  2072. * Sets the value of the supplied hash key
  2073. * @param String The name of the hash key
  2074. * @param String The value of the hash key
  2075. */
  2076. function setHashParam(key, val) {
  2077. var hashString = '#!';
  2078. var params = getHashParams();
  2079. params[key] = val;
  2080. for (key in params) {
  2081. hashString += '/' + key + '/' + params[key];
  2082. }
  2083. history.replaceState(null, null, hashString);
  2084. }
  2085.  
  2086. /**
  2087. * Removes a hash key/value pair from the location hash
  2088. * @param String The name of the hash key
  2089. */
  2090. function unsetHashParam(key) {
  2091. var current = getHashParam(key);
  2092. if (typeof current !== 'undefined')
  2093. history.replaceState(null, null, window.location.hash.replace('/' + key + '/' + current, ''));
  2094. }
  2095.  
  2096.  
  2097.  
  2098. /* ===== Gallery CSS =====
  2099. The CSS for the rebuilt gallery page with theme support
  2100. */
  2101.  
  2102. /**
  2103. * Generates the CSS used for the rebuilt gallery page
  2104. * @param String (Optional) Additional CSS
  2105. * @return String The CSS for the rebuilt gallery page
  2106. */
  2107. function getCSS(css) {
  2108. css = (typeof css === "undefined") ? '' : css;
  2109.  
  2110. initSettings('theme');
  2111. switch(getHashParam('theme') || settings.theme.value) {
  2112. case 'blue':
  2113. var bg1 = '#060D1A';
  2114. var bg2 = '#03060D';
  2115. var fg1 = '#557799';
  2116. var fg2 = '#557799';
  2117. var links = '#AABBCC';
  2118. var accent1 = '#6699CC';
  2119. var accent2 = '#6699CC';
  2120. break;
  2121.  
  2122. case 'classic':
  2123. var bg1 = '#FFFFFF';
  2124. var bg2 = '#3366CC';
  2125. var fg1 = '#666666';
  2126. var fg2 = '#AACCEE';
  2127. var links = '#AACCEE';
  2128. var accent1 = '#3366CC';
  2129. var accent2 = '#FFFFFF';
  2130. break;
  2131.  
  2132. case 'green':
  2133. var bg1 = '#FFFFFF';
  2134. var bg2 = '#222222';
  2135. var fg1 = '#888888';
  2136. var fg2 = '#888888';
  2137. var links = '#AAAAAA';
  2138. var accent1 = '#33AA00';
  2139. var accent2 = '#66CC33';
  2140. break;
  2141.  
  2142. case 'default':
  2143. default:
  2144. var bg1 = '#222222';
  2145. var bg2 = '#111111';
  2146. var fg1 = '#888888';
  2147. var fg2 = '#888888';
  2148. var links = '#AAAAAA';
  2149. var accent1 = '#3380CC';
  2150. var accent2 = '#3380CC';
  2151. break;
  2152. }
  2153.  
  2154. /**
  2155. * Darkens a color by a specified amount
  2156. * @param String The RGB hex color code
  2157. * @param Int The amount (decimal-format pertentage) by which to darken the color
  2158. * @return String The color code for the darkened color
  2159. */
  2160. function darken(color, amount) {
  2161. color = splitColor(color);
  2162. var ret = [];
  2163. for (var i = 0; i < color.length; i++) {
  2164. ret[i] = (color[i] - Math.ceil(255 * amount));
  2165.  
  2166. if (ret[i] < 0)
  2167. ret[i] = 0;
  2168. if (ret[i] > 255)
  2169. ret[i] = 255;
  2170.  
  2171. ret[i] = ret[i].toString(16);
  2172. if (ret[i].length < 2)
  2173. ret[i] = '0' + ret[i];
  2174. }
  2175. return '#' + ret.join('').toUpperCase();
  2176. }
  2177.  
  2178. /**
  2179. * Lightens a color by a specified amount
  2180. * @param String The RGB hex color code
  2181. * @param Int The amount (decimal-format pertentage) by which to lighten the color
  2182. * @return String The color code for the lightened color
  2183. */
  2184. function lighten(color, amount) {
  2185. color = splitColor(color);
  2186. var ret = [];
  2187. for (var i = 0; i < color.length; i++) {
  2188. ret[i] = (color[i] + Math.ceil(255 * amount));
  2189.  
  2190. if (ret[i] < 0)
  2191. ret[i] = 0;
  2192. if (ret[i] > 255)
  2193. ret[i] = 255;
  2194.  
  2195. ret[i] = ret[i].toString(16);
  2196. if (ret[i].length < 2)
  2197. ret[i] = '0' + ret[i];
  2198. }
  2199. return '#' + ret.join('').toUpperCase();
  2200. }
  2201.  
  2202. /**
  2203. * Converts a color code into a usable array for math-based functions
  2204. * @param String The RGB hex color code
  2205. * @return Int[] The array containing the decimal values of each color
  2206. */
  2207. function splitColor(color) {
  2208. color = color.replace('#', '');
  2209.  
  2210. var offset = Math.floor(color.length / 3);
  2211. var ret = [];
  2212. for (var i = 0; i < color.length; i+=offset) {
  2213. ret.push(parseInt(color.substring(i, (i + offset)), 16));
  2214. }
  2215. return ret;
  2216. }
  2217.  
  2218. /**
  2219. * Returns the CSS for a vertical background gradient (with vendor-specific prefixes)
  2220. * @param String The RGB hex color code of the top color
  2221. * @param String The RGB hex color code of the bottom color
  2222. * @return String The CSS for the background gradient
  2223. */
  2224. function gradient(top, bottom) {
  2225. var ret = '';
  2226. ret += 'background: -moz-linear-gradient(top, ' + top + ' 0%, ' + bottom + ' 100%);';
  2227. ret += 'background: -webkit-linear-gradient(top, ' + top + ' 0%, ' + bottom + ' 100%);';
  2228. return ret;
  2229. }
  2230.  
  2231. /**
  2232. * Returns the CSS for rounded corners (with vendor-specific prefixes)
  2233. * @param String The radius value (syntax: '#px' or '#px #px #px #px')
  2234. * @return String The CSS for the rounded corners
  2235. */
  2236. function borderRadius(radius) {
  2237. radius = 'border-radius: ' + radius;
  2238. // returns: -moz-border-radius: <radius>; -webkit-border-radius: <radius>; border-radius: <radius>;
  2239. return '-moz-' + radius + '; ' + '-webkit-' + radius + '; ' + radius + ';';
  2240. }
  2241.  
  2242. /**
  2243. * Returns the CSS for box shadows (with vendor-specific prefixes)
  2244. * @param String The shadow value (syntax: '#px #px [#px] [#px] color [inset]')
  2245. * @return String The CSS for the box shadows
  2246. */
  2247. function boxShadow(shadow) {
  2248. shadow = 'box-shadow: ' + shadow;
  2249. // returns: -moz-box-shadow: <shadow>; -webkit-box-shadow: <shadow>; box-shadow: <shadow>;
  2250. return '-moz-' + shadow + '; ' + '-webkit-' + shadow + '; ' + shadow + ';';
  2251. }
  2252.  
  2253. // basics
  2254. css += '* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; margin: 0; padding: 0; }';
  2255. css += 'body { background-color: ' + bg1 + '; color: ' + fg1 + '; font: 13px Helvetica, Arial, sans-serif; }';
  2256. css += 'a { color: ' + links + '; cursor: pointer; text-decoration: underline; }';
  2257. css += 'a:hover, a:hover { color: ' + lighten(links, 0.133) + '; text-decoration: none; }';
  2258. css += 'p { margin: 0 0 10px; }';
  2259. css += 'table { font: 13px Helvetica, Arial, sans-serif; margin: auto; width: 100%; }';
  2260.  
  2261. // layout
  2262. css += '#header { background-color: ' + bg2 + '; border-bottom: 1px solid ' + lighten(bg1, 0.066) + '; color: '+ fg2 + '; padding: 10px 0 0; text-align: center; }';
  2263. css += '.scrolling #header { margin-bottom: 10px; }';
  2264. css += '.slideshow #header { min-height: 60px; position: fixed; top: 0; width: 100%; z-index: 2; }';
  2265. css += '#header .title { color: ' + accent2 + '; }';
  2266. css += '#header small { font-variant: small-caps; }';
  2267. css += '#header p { margin: 10px 0; }';
  2268. css += '#header #description { margin: 10px auto; max-width: 60%; text-align: center; }';
  2269. css += '#search { position: absolute; right: 10px; top: 10px; }';
  2270. css += '#footer { background-color: ' + bg2 + '; border-top: 1px solid ' + lighten(bg1, 0.066) + '; color: '+ fg2 + '; min-height: 60px; padding: 10px 0; position: relative; text-align: center; }';
  2271. css += '.scrolling #footer { margin-top: 10px; position: fixed; bottom: 0; left: 0; right: 0; }';
  2272. css += '.slideshow #footer { bottom: 0; height: 60px; position: fixed; width: 100%; z-index: 2; }';
  2273. css += '#favorites_container { height: 40px; line-height: 40px; margin-bottom: 0 !important; position: absolute; left: 25px; bottom: 10px; }';
  2274. css += '#autoplay { height: 20px; line-height: 20px; position: absolute; right: 25px; bottom: 20px; }';
  2275. css += '#info { font-size: 11px; margin: 10px 0 0; }';
  2276.  
  2277. // logo
  2278. css += '#logo { text-decoration: none; position: absolute; left: 10px; top: 10px; }';
  2279. css += '#logo span { font: 18px "Comic Sans MS"; padding: 0 2px; }';
  2280. css += '#logo .image { background-color: ' + bg1 + '; color: ' + accent1 + '; }';
  2281. css += '#logo:hover .image { background-color: ' + accent1 + '; color: ' + bg1 + '; }';
  2282. css += '#logo .fap { background-color: ' + accent1 + '; color: ' + bg1 + '; }';
  2283. css += '#logo:hover .fap { background-color: ' + bg1 + '; color: ' + accent1 + '; }';
  2284.  
  2285. // forms
  2286. css += 'form { margin: 0 0 10px; }';
  2287. css += 'input[type="text"], select { background: ' + bg1 + '; border: 1px solid ' + fg1 + '; color: ' + fg1 + '; margin-right: 5px; padding: 5px; }';
  2288. css += 'input[type="text"]:focus, select:focus { border-color: ' + accent1 + '; color: ' + fg1 + '; }';
  2289. css += 'button, input[type="button"], input[type="submit"] { background: ' + lighten(bg2, 0.066) + '; ' + gradient(lighten(bg2, 0.133), lighten(bg2, 0.066)) + '; border: 1px solid ' + lighten(bg2, 0.200) + '; ' + borderRadius('5px') + ' color: ' + links + '; cursor: pointer; margin-left: 5px; padding: 5px; ' + boxShadow('0 0 0 1px ' + bg2) + '; }';
  2290. css += 'button:hover, input[type="button"]:hover, input[type="submit"]:hover { ' + gradient(lighten(bg2, 0.200), lighten(bg2, 0.066)) + '; border: 1px solid ' + lighten(bg2, 0.266) + '; color: ' + lighten(links, 0.066) + '; }';
  2291. css += 'button:focus, input[type="button"]:focus, input[type="submit"]:focus { ' + gradient(lighten(bg2, 0.266), lighten(bg2, 0.066)) + '; border: 2px solid ' + lighten(bg2, 0.333) + '; color: ' + lighten(links, 0.133) + '; padding: 4px; }';
  2292.  
  2293. css += '#favorites_container input[type="button"], button.default, input[type="submit"] { border: 1px solid ' + accent1 + '; color: ' + lighten(links, 0.133) + '; }';
  2294. css += '#favorites_container input[type="button"]:hover, button.default:hover, input[type="submit"]:hover { border: 1px solid ' + lighten(accent1, 0.066) + '; color: ' + lighten(links, 0.200) + '; }';
  2295. css += '#favorites_container input[type="button"]:focus, button.default:focus, input[type="submit"]:focus { border: 2px solid ' + lighten(accent1, 0.066) + '; color: ' + lighten(links, 0.266) + '; padding: 4px; }';
  2296.  
  2297. // pagination
  2298. css += '.pagination { margin: 0; }';
  2299. css += '.pagination a { border: 1px solid ' + darken(links, 0.133) + '; color: ' + darken(links, 0.133) + '; display: inline-block; margin: 0 2px 10px; padding: 2px 6px; text-decoration: none; }';
  2300. css += '.pagination a:hover { border-color: ' + links + '; color: ' + links + '; display: inline-block; margin: 0 2px; padding: 2px 6px; text-decoration: none; }';
  2301. css += '.pagination a.current { border: 1px solid ' + accent2 + '; color: ' + accent2 + '; }';
  2302. css += '.pagination a.disabled { border: 1px solid ' + darken(fg2, 0.266) + '; color: ' + darken(fg2, 0.133) + '; cursor: default; display: inline-block; margin: 0 2px; padding: 2px 6px; }';
  2303.  
  2304. // thumbnails
  2305. css += '#thumbnails { margin-bottom: 10px; text-align: center; z-index: 2; }';
  2306. css += '#thumbnails .thumbnail { border: 1px solid ' + darken(links, 0.133) + '; display: inline-block; margin: 2px; padding: 4px; vertical-align: middle; }';
  2307. css += '#thumbnails .thumbnail:hover { border-color: ' + links + '; }';
  2308. css += '#thumbnails .thumbnail.active { border: 2px solid ' + accent2 + '; padding: 3px; }';
  2309. css += '#thumbnails.small img { max-height: 100px; }';
  2310. css += '#thumbnails.medium img { max-height: 150px; }';
  2311. css += '#thumbnails.large img { max-height: 200px; }';
  2312. css += '.slideshow #thumbnails { background-color: ' + bg2 + '; padding-bottom: 10px; overflow-y: hidden; width: 100%; white-space: nowrap; }';
  2313. css += '.slideshow #thumbnails .thumbnail { margin: 0 5px; }';
  2314.  
  2315. // gallery basics
  2316. css += '#gallery { position: relative; text-align: center; }';
  2317. css += '#gallery .image img { border: 1px solid ' + darken(links, 0.133) + '; padding: 4px; min-height: 100px; min-width: 100px; }';
  2318. css += '#gallery .image:hover img { border-color: ' + accent1 + '; }';
  2319. css += '#gallery .image .spinner { border: 10px solid ' + darken(fg2, 0.266) + '; border-left-color: ' + accent1 + '; position: absolute; left: calc(100% / 2 - 80px / 2); top: calc(100% / 2 - 80px / 2); -webkit-animation: spinning 1s infinite linear; animation: spinning 1s infinite linear; }';
  2320. css += '#gallery .image .spinner, #gallery .image .spinner:after { ' + borderRadius('50%') + '; width: 80px; height: 80px; z-index: -1; }';
  2321. css += '@-webkit-keyframes spinning { 0% { -webkit-transform: rotate(0deg); transform: rotate(0deg); } 100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); } }';
  2322. css += '@keyframes spinning { 0% { -webkit-transform: rotate(0deg); transform: rotate(0deg); } 100% { -webkit-transform: rotate(360deg); transform: rotate(360deg); } }';
  2323.  
  2324. // scrolling gallery
  2325. css += '.scrolling #gallery { max-width: 100%; }';
  2326. css += '.scrolling #gallery .image { clear: both; display: inline-block; max-width: 98%; position: relative; }';
  2327. css += '.scrolling #gallery .image img { display: inline-block; max-width: 100%; }';
  2328.  
  2329. css += '#loader { background: ' + lighten(bg2, 0.066) + '; ' + gradient(lighten(bg2, 0.133), lighten(bg2, 0.066)) + '; border: 1px solid ' + accent1 + '; border-radius: 5px; ' + boxShadow('0 0 0 1px ' + bg2) + '; color: ' + lighten(links, 0.133) + '; display: inline-block; margin-top: 10px; padding: 8px 16px; text-decoration: none; }';
  2330. css += '#loader:hover { ' + gradient(lighten(bg2, 0.200), lighten(bg2, 0.066)) + '; border-color: ' + lighten(accent1, 0.066) + '; color: ' + lighten(links, 0.200) + '; }';
  2331.  
  2332. // slideshow gallery
  2333. css += '.slideshow #content { bottom: 81px; left: 0; padding: 10px; position: absolute; right: 0; top: 81px; }';
  2334. css += '.slideshow #gallery { height: 100%; width: 100%; overflow: hidden; }';
  2335. css += '.slideshow #gallery .image img { bottom: 0; left: 0; margin: auto; max-height: 100%; max-width: 100%; position: absolute; right: 0; top: 0; }';
  2336. css += '.slideshow #gallery .nav { color: #FFFFFF; display: block; text-decoration: none; opacity: 0.5; position: absolute; top: 5px; bottom: 5px; height: 100%; width: 160px; z-index: 1; }';
  2337. css += '.slideshow #gallery .nav.disabled { display: none; }';
  2338. css += '.slideshow #gallery #next { min-height: 60px; min-width: 60px; right: 5px; }';
  2339. css += '.slideshow #gallery #prev { min-height: 60px; min-width: 60px; left: 5px; }';
  2340. css += '.slideshow #gallery .arrow { display: block; font-size: 120px; height: 160px; line-height: 160px; margin-top: -80px; position: relative; text-align: center; text-shadow: 0 0 5px #000000, 0 0 20px #FFFFFF; top: 50%; }';
  2341. css += '.slideshow #gallery .nav:hover { background-color: rgba(0,0,0,0.5); opacity: 1.0; }';
  2342. css += '.slideshow #gallery #indicator { background-color: rgba(0,0,0,0.5); ' + borderRadius('40px') + '; display: block; position: absolute; top: 50%; left: 50%; height: 160px; margin-top: -80px; margin-left: -80px; width: 160px; z-index: 1; }';
  2343. css += '.slideshow #gallery #indicator .symbol { color: #FFFFFF; font-size: 120px; position: relative; text-align: center; text-shadow: 0 0 5px #000000, 0 0 20px #FFFFFF; }';
  2344. css += '.slideshow #gallery #indicator .symbol.pause { font-weight: bold; }';
  2345. css += '.slideshow #gallery #indicator .symbol.play { line-height: 160px; }';
  2346.  
  2347. // full screen:: WebKit
  2348. css += ':-webkit-full-screen { background-color: #000000; }';
  2349. css += '#content:-webkit-full-screen { padding: 0; top: 0 !important; bottom: 0 !important; height: 100%; width: 100%; }';
  2350. css += '#content:-webkit-full-screen .nav { ' + borderRadius('40px') + '; height: 160px; margin-top: -80px; top: 50%; }';
  2351. css += '#content:-webkit-full-screen .image img { border: 0; padding: 0; }';
  2352. css += '#content:-webkit-full-screen #thumbnails { background-color: #000000; position: absolute; top: 0; }';
  2353. // full screen:: Mozilla
  2354. css += '#content:-moz-full-screen { padding: 0; top: 0 !important; bottom: 0 !important; height: 100%; width: 100%; }';
  2355. css += '#content:-moz-full-screen .nav { ' + borderRadius('40px') + '; height: 160px; margin-top: -80px; top: 50%; }';
  2356. css += '#content:-moz-full-screen .image img { border: 0; padding: 0; }';
  2357. css += '#content:-moz-full-screen #thumbnails { background-color: #000000; position: absolute; top: 0; }';
  2358.  
  2359. // add to favorites
  2360. css += '#favorites_container table { width: auto; }';
  2361.  
  2362. // notification messages
  2363. css += '#notificationContainer { bottom: 70px; position: fixed; right: 10px; }';
  2364. css += '.notification { background: rgba(0, 0, 0, 0.8); border: 1px solid rgba(255, 255, 255, 0.2); ' + borderRadius('5px') + '; color: rgba(255, 255, 255, 0.5); display: block; font-size: 11px; margin-top: 10px; padding: 9px; }';
  2365.  
  2366. // dialog box layout
  2367. css += '#dialogContainer { background: rgba(0,0,0,0.8); display: block; text-align: center; position: fixed; top: 0; bottom: 0; left: 0; right: 0; z-index: 3; overflow-y: auto; }';
  2368. css += '#dialogBox { background: ' + bg1 + '; border: 1px solid ' + lighten(bg2, 0.200) + '; ' + boxShadow('0 0 20px 0 #000000') + '; color: ' + fg1 + '; display: inline-block; margin: 20px auto; min-width: 300px; text-align: left; position: relative; z-index: 10; }';
  2369. css += '#dialogClose { border-left: 1px solid ' + lighten(bg2, 0.200) + '; color: ' + links + '; font-size: 14px; line-height: 28px; position: absolute; right: 0; text-align: center; text-decoration: none; top: 0; width: 30px; }';
  2370. css += '#dialogClose:hover { color: ' + lighten(links, 0.200) + '; }';
  2371. css += '#dialogTitle { background: ' + bg1 + '; ' + gradient(lighten(bg2, 0.066), bg2) + '; border-bottom: 1px solid ' + lighten(bg2, 0.200) + '; color: ' + links + '; display: block; margin: 0; padding: 5px 10px; }';
  2372. css += '#dialogTitle b { color: ' + accent2 + '; }';
  2373. css += '#dialogMessage { display: block; padding: 10px; }';
  2374. css += '#dialogButtons { clear: both; display: block; padding: 10px; text-align: right; }';
  2375.  
  2376. // dialog box content
  2377. css += '#dialogMessage table { margin: 0; }';
  2378. css += '#dialogMessage table th { color: ' + accent1 + '; font-size: 14px; text-align: left; }';
  2379. css += '#dialogMessage table b { color: ' + lighten(accent1, 0.066) + '; }';
  2380. css += '#dialogMessage table td.name { padding-right: 5%; text-align: right; width: 20%; }';
  2381. css += '#dialogMessage table td.key { text-align: center; width: 25%; }';
  2382.  
  2383. // dialog box form elements
  2384. css += '#dialogBox #settingsForm { width: 820px }';
  2385. css += '#dialogBox .error { color: #C43131; font-weight: bold; }';
  2386. css += '#dialogBox button { margin-right: 5px; }';
  2387. css += '#dialogBox fieldset { border: 0; border-bottom: 1px solid ' + lighten(bg2, 0.200) + '; margin: 0 0 15px; padding-bottom: 10px; min-width: 400px; }';
  2388. css += '#dialogBox fieldset:nth-child(1n) { float: left; }';
  2389. css += '#dialogBox fieldset:nth-child(2n) { float: right; }';
  2390. css += '#dialogBox legend { color: ' + accent1 + '; font-weight: bold; margin-bottom: 10px; }';
  2391. css += '#dialogBox label { float: left; line-height: 20px; }';
  2392. css += '#dialogBox label b { color: ' + accent1 + '; }';
  2393. css += '#dialogBox label span.default { font-size: 11px; font-variant: small-caps; }';
  2394. css += '#dialogBox input[type="text"], #dialogBox select { float: right; }';
  2395. css += '#dialogBox input[type="checkbox"] { float: left; margin: 4px 10px 0 ; }';
  2396.  
  2397. // insert the line breaks automatically before returning
  2398. return css.replace(/}/g, "}\n");
  2399. }