MassiveFap

A complete ImageFap.com gallery conversion script featuring customization options and multiple viewing modes. Original author is Ryan Thaut, but it looks like abandoned.

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