Hover Zoom Minus --

image popup: zoom, pan, scroll, pin, scale

当前为 2024-04-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hover Zoom Minus --
  3. // @namespace Hover Zoom Minus --
  4. // @version 1.0.9.8
  5. // @description image popup: zoom, pan, scroll, pin, scale
  6. // @author Ein, Copilot AI
  7. // @match *://*/*
  8. // @license MIT
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. // 01. to use hover over the image(container) to view a popup of the target image
  13. // 02. to zoom in/out use wheel up/down.
  14. // 03. click left mouse to lock popup this will make it move along with the mouse, click again to release (indicated by green border)
  15. // 04. while being locked"Y" the wheel up/down will act as scroll up/down
  16. // 05. double click will lock it on screen preventing it from being hidden
  17. // 06. hover below the image and click blue bar this will make a 3rd mode for wheel bottom, which will scroll next/previous image under an album
  18. // 07. while locked at screen (indicated by red outline) a single click with the blurred background will unblur it, only one popup per time, so the locked popup will prevent other popup to spawn
  19. // 08. double clicking on blurred background will de-spawn popup
  20. // 09. click on the corner to toggle scaling (blue) will retain current aspect ratio, double clicking will turn to 2nd mode for scaling (magenta) will not retain current aspect ratio
  21. // 10. return to original aspect ration via clicking on sides, if it's in an album to reset to aspect ratio on bottom side use double click
  22. // 11. you can now crop and save the image, just double click the top to initiate.
  23. // 12. to turn on/off hover at the bottom of the page
  24.  
  25. (function() {
  26. 'use strict';
  27.  
  28. // Configuration ----------------------------------------------------------
  29.  
  30. // Define regexp of web page you want HoverZoomMinus to run with,
  31. // 1st array value - default status at start of page: '1' for on, '0' for off
  32. // 2nd array value - spawn position for popup: 'center' for center of screen, '' for cursor position
  33. // 3rd array value - allowed interval for spawning popup; i.e. when exited on popup but immediately touches an img container thus making it "blink spawn blink spawn", experiment it with the right number
  34.  
  35. const siteConfig = {
  36. 'reddit.com': [1, 'center', '100'],
  37. '9gag.com': [1, 'center', '0'],
  38. 'feedly.com': [1, 'center', '200'],
  39. '4chan.org': [1, '', '400'],
  40. 'deviantart.com': [0, 'center', '300'],
  41. 'home': [1, 'center', '0'] /* for testing */
  42. };
  43.  
  44. // image container [hover box where popup triggers]
  45. const imgContainers = `
  46. /* ------- reddit */ ._3BxRNDoASi9FbGX01ewiLg, ._3Oa0THmZ3f5iZXAQ0hBJ0k > div, ._35oEP5zLnhKEbj5BlkTBUA, ._1ti9kvv_PMZEF2phzAjsGW > div,
  47. /* ------- reddit */ ._28TEYBuEdOuE3kN6UyoKMa div, ._3Oa0THmZ3f5iZXAQ0hBJ0k.WjuR4W-BBrvdtABBeKUMx div, ._3m20hIKOhTTeMgPnfMbVNN, zoomable-img.fixed,
  48. /* --------- 9gag */ .post-container .post-view,
  49. /* ------- feedly */ .PinableImageContainer, .entryBody,
  50. /* -------- 4chan */ div.post div.file a,
  51. /* --- deviantart */ ._3_LJY, ._2e1g3, ._2SlAD, ._1R2x6
  52. `;
  53. // target img
  54. const imgElements = `
  55. /* ------- reddit */ ._2_tDEnGMLxpM6uOa2kaDB3, ._1dwExqTGJH2jnA-MYGkEL-, ._2_tDEnGMLxpM6uOa2kaDB3._1XWObl-3b9tPy64oaG6fax, zoomable-img.fixed img,
  56. /* --------- 9gag */ .post-container .post-view > picture > img,
  57. /* ------- feedly */ .pinable, .entryBody img,
  58. /* -------- 4chan */ div.post div.file img:nth-child(1), ._3Oa0THmZ3f5iZXAQ0hBJ0k.WjuR4W-BBrvdtABBeKUMx img, div.post div.file .fileThumb img,
  59. /* --- deviantart */ ._3_LJY img, ._2e1g3 img, ._2SlAD img, ._1R2x6 img
  60. `;
  61. // excluded element
  62. const nopeElements = `
  63. /* ------- reddit */ ._2ED-O3JtIcOqp8iIL1G5cg
  64. `;
  65. // AlbumSelector take note that it will only load image that are already in the DOM tree
  66. // example reddit will not include all until you press navigator buttons so most of the time this will only load a few image
  67. // unless you update it via interacting with navigator button thus updating the DOM tree (added new function for navigation it can now update)
  68. let albumSelector = [
  69. /* ---reddit */ { imgElement: '._1dwExqTGJH2jnA-MYGkEL-', albumElements: '._1apobczT0TzIKMWpza0OhL' },
  70. /* ---feedly */ { imgElement: '.entryBody > div > img', albumElements: '.entryBody > div' },
  71. /* ---feedly */ { imgElement: 'div[id^="Article-"] > div > span > img', albumElements: 'div[id^="Article-"]' },
  72. ];
  73.  
  74. // specialElements were if targeted, will call it's paired function
  75. // for convenience an element className "specialElement" will be remove during mouseout or function hidepopup() is called you can use that with specialElements function for temporary elements
  76. const specialElements = [
  77. /* --- 4chan */ { selector: 'div.post div.file .fileThumb img', func: SP1 },
  78. /* -- reddit */ { selector: '._1dwExqTGJH2jnA-MYGkEL-', func: SP2 },
  79. /* -- reddit */ { selector: '._2_tDEnGMLxpM6uOa2kaDB3', func: SPunblurSpoiler }
  80. ];
  81. // special function triggered when clicking LeftBar/ wheel down in album mode
  82. const specialLeftBar = [
  83. /* -- reddit */ { selector: '._1dwExqTGJH2jnA-MYGkEL-', func: SPL }
  84. ];
  85. // special function triggered when clicking RightBar/ wheel up in album mode
  86. const specialRightBar = [
  87. /* -- reddit */ { selector: '._1dwExqTGJH2jnA-MYGkEL-', func: SPR }
  88. ];
  89. //-------------------------------------------------------------------------
  90. // Special Funtions -------------------------------------------------------
  91.  
  92.  
  93. // 4chan: replaces thumbnail so popup will use the larger version, or if its animated replace it with that
  94. function SP1(imageElement) {
  95. const parentElement = imageElement.parentElement;
  96. const href = parentElement.getAttribute('href');
  97. if (parentElement.tagName === 'a') {
  98. if (href.endsWith('.webm')) {
  99. const videoElement = document.createElement('video');
  100. videoElement.src = href;
  101. videoElement.controls = true;
  102. parentElement.replaceChild(videoElement, imageElement);
  103. } else {
  104. imageElement.setAttribute('src', href);
  105. }
  106. } else {
  107. imageElement.setAttribute('src', href);
  108. }
  109. }
  110.  
  111. // reddit: added the label/description of image along with the popup
  112. function SP2(imageElement) {
  113. if (enableP === 0) {
  114. return;
  115. }
  116. let closestElement = imageElement.closest('.m3aNC6yp8RrNM_-a0rrfa, .kcerW9lbT-se3SXd-wp2i');
  117. if (!closestElement) {
  118. return;
  119. }
  120. let descendantElement = closestElement.querySelector('._15nNdGlBIgryHV04IfAfpA');
  121. if (descendantElement) {
  122. document.querySelectorAll('.specialElement').forEach(e => e.remove());
  123. let title = descendantElement.getAttribute('title');
  124. const specialContent = document.createElement('div');
  125. specialContent.className = 'specialElement';
  126. specialContent.style.cssText = 'position:fixed; bottom:80px; left:50%; transform:translateX(-50%); width:100vw; text-align:center; font-size:40px; color:white; text-shadow:0 0 10px rgba(255,255,255,0.7); z-index:99999;';
  127. specialContent.textContent = title;
  128. document.body.appendChild(specialContent);
  129.  
  130. var specialBackdrop = document.createElement('div');
  131. specialBackdrop.className = 'specialElement';
  132. specialBackdrop.style.cssText = 'position:fixed; bottom:60px; left:0; width:100vw; height:80px; background:rgba(0,0,0,0.2); backdrop-filter:blur(5px); z-index:99998;';
  133. document.body.appendChild(specialBackdrop);
  134.  
  135. } else {
  136. return;
  137. }
  138. }
  139. function SPL(imageElement) {
  140. document.querySelectorAll('.specialElement').forEach(e => e.remove());
  141.  
  142. let closestElement = imageElement.closest('.kcerW9lbT-se3SXd-wp2i');
  143. var element = closestElement.querySelector('._1fSFPkxZ9pToLETLQT2dmc');
  144. if (element) element.click();
  145.  
  146. let descendantElement = closestElement.querySelector('._15nNdGlBIgryHV04IfAfpA');
  147. if (descendantElement) {
  148. let title = descendantElement.getAttribute('title');
  149. const specialContent = document.createElement('div');
  150. specialContent.className = 'specialElement';
  151. specialContent.style.cssText = 'position:fixed; bottom:80px; left:50%; transform:translateX(-50%); width:100vw; text-align:center; font-size:40px; color:white; text-shadow:0 0 10px rgba(255,255,255,0.7); z-index:99999;';
  152. specialContent.textContent = title;
  153. document.body.appendChild(specialContent);
  154.  
  155. var specialBackdrop = document.createElement('div');
  156. specialBackdrop.className = 'specialElement';
  157. specialBackdrop.style.cssText = 'position:fixed; bottom:60px; left:0; width:100vw; height:80px; background:rgba(0,0,0,0.2); backdrop-filter:blur(5px); z-index:99998;';
  158. document.body.appendChild(specialBackdrop);
  159. } else {
  160. return;
  161. }
  162. }
  163. function SPR(imageElement) {
  164. document.querySelectorAll('.specialElement').forEach(e => e.remove());
  165.  
  166. let closestElement = imageElement.closest('.kcerW9lbT-se3SXd-wp2i');
  167. var element = closestElement.querySelector('._3-JCOd-nY76g29C7ZVX_kl:last-child');
  168. if (element) element.click();
  169.  
  170. let descendantElement = closestElement.querySelector('._15nNdGlBIgryHV04IfAfpA');
  171. if (descendantElement) {
  172. let title = descendantElement.getAttribute('title');
  173. const specialContent = document.createElement('div');
  174. specialContent.className = 'specialElement';
  175. specialContent.style.cssText = 'position:fixed; bottom:80px; left:50%; transform:translateX(-50%); width:100vw; text-align:center; font-size:40px; color:white; text-shadow:0 0 10px rgba(255,255,255,0.7); z-index:99999;';
  176. specialContent.textContent = title;
  177. document.body.appendChild(specialContent);
  178.  
  179. var specialBackdrop = document.createElement('div');
  180. specialBackdrop.className = 'specialElement';
  181. specialBackdrop.style.cssText = 'position:fixed; bottom:60px; left:0; width:100vw; height:80px; background:rgba(0,0,0,0.2); backdrop-filter:blur(5px); z-index:99998;';
  182. document.body.appendChild(specialBackdrop);
  183. } else {
  184. return;
  185. }
  186. }
  187.  
  188. // reddit: unblur spoiler, from https://greasyfork.org/en/scripts/479784-reddit-show-images-marked-with-spoiler-nsfw
  189. function SPunblurSpoiler(imageElement) {
  190. const regexIdImg = /https:\/\/.*\/(.*)\?/;
  191.  
  192. const imgs = imageElement.parentElement.querySelectorAll('._2_tDEnGMLxpM6uOa2kaDB3[src*="?blur="]');
  193. imgs.forEach(img => {
  194. img.src = `https://i.redd.it/${img.src.match(regexIdImg)[1]}`;
  195. img.classList.remove('_3oBPn1sFwq76ZAxXgwRhhn');
  196. });
  197.  
  198. let descendantElement = imageElement.closest('.m3aNC6yp8RrNM_-a0rrfa');
  199. if (descendantElement) {
  200. descendantElement.style.background = '#0000';
  201. let removeElement = descendantElement.querySelector('._2iaYXFpGyyEGq1rp02cl5w');
  202. if (removeElement) {
  203. removeElement.style.display = 'none';
  204. }
  205. }
  206. }
  207.  
  208. //-------------------------------------------------------------------------
  209.  
  210.  
  211. // Configuration variables
  212. const currentHref = window.location.href;
  213. let enableP, positionP, intervalP, URLmatched;
  214. Object.keys(siteConfig).some((config) => {
  215. const regex = new RegExp(config);
  216. if (currentHref.match(regex)) {
  217. [enableP, positionP, intervalP] = siteConfig[config];
  218. URLmatched = true;
  219. return true;
  220. }
  221. });
  222.  
  223.  
  224. // The HoverZoomMinus Function---------------------------------------------
  225. function HoverZoomMinus() {
  226. let isshowPopupEnabled = true;
  227. isshowPopupEnabled = true;
  228.  
  229. const style = document.createElement('style');
  230. style.type = 'text/css';
  231. style.innerHTML = `
  232. .popup-container { display:none; cursor: move; z-index:1001; }
  233. .popup-image { max-height:calc(90vh - 10px); display:none; }
  234. .popup-backdrop { position:fixed; top:0; left:0; width:100vw; height:100vh; display:none; z-index:1000; }
  235. .centerBox { top:40px; left:40px; position:absolute; height:calc(100% - 80px); width:calc(100% - 80px); z-index:9999; }
  236. .TopBar, .BottomBar, .LeftBar, .RightBar {
  237. opacity:0; box-sizing:border-box; background:#0000; position:absolute; z-index:9999;
  238. &::after { content:""; position:absolute; }
  239. }
  240. .TopBar, .BottomBar { height:40px; width:calc(100% - 80px); left:40px;
  241. &::after { display:none; width:25px; height:25px; transform:rotate(45deg) translateX(-50%) translateY(-50%); }
  242. }
  243. .TopBar { top:0; }
  244. .BottomBar { bottom:0; }
  245. .TopBar::after { left:calc(50% - 17px); top:calc(50% + 15px); border-top:5px solid #6f8e9e; border-left:5px solid #6f8e9e; }
  246. .BottomBar::after { left:calc(50% - 2px); bottom:-8px; border-bottom:5px solid #6f8e9e; border-right: 5px solid #6f8e9e; }
  247. .LeftBar, .RightBar {
  248. height:calc(100% - 80px); width:40px; top:40px;
  249. &::before { content:""; display:block; position:absolute; top:50%; width:40px; height:40px; transform:translateY(-50%); border-radius:9999px; background: #242526; }
  250. &::after { content:""; display:block; position:absolute; top:calc(50% + -2px); width:15px; height:15px; }
  251. &:hover::before { display:none; }
  252. &:hover::after { width:25px; height:25px; border-color:#6f8e9e; border-width:5px; }
  253. }
  254. .LeftBar { left:0; }
  255. .RightBar { right:0; }
  256. .LeftBar::before { left:5px; opacity:0 }
  257. .RightBar::before { right:5px; opacity:0 }
  258. .LeftBar:hover::after { left:3px; }
  259. .RightBar:hover::after { right:3px; }
  260. .LeftBar::after { transform:rotate(45deg) translateY(-50%); border-bottom:3px solid #777; border-left:3px solid #777; left:12px; opacity:0 }
  261. .RightBar::after { transform:rotate(-45deg) translateY(-50%); border-bottom: 3px solid #777; border-right:3px solid #777; right:12px; opacity:0 }
  262. .popup-container:hover { .LeftBar::before, .RightBar::before, .LeftBar::after, .RightBar::after, .CornerBox.TR { opacity:1 }}
  263. .CornerBox { box-sizing:border-box; height:40px; width:40px; background:#0000; position:absolute; z-index:9999; }
  264. .CornerBox.TR { top:0; right:0; font-size:11px; text-align:center; line-height:25px; color:white; text-shadow:0 0 4px rgba(255,255,255,0.7); opacity:0 }
  265. .CornerBox.TL { top:0; left:0; }
  266. .CornerBox.BR { bottom:0; right:0; }
  267. .CornerBox.BL { bottom:0; left:0;}
  268. `;
  269.  
  270. document.head.appendChild(style);
  271. const backdrop = document.createElement('div');
  272. backdrop.className = 'popup-backdrop';
  273. document.body.appendChild(backdrop);
  274. const popupContainer = document.createElement('div');
  275. popupContainer.className = 'popup-container';
  276. document.body.appendChild(popupContainer);
  277. const popup = document.createElement('img');
  278. popup.className = 'popup-image';
  279. popupContainer.appendChild(popup);
  280.  
  281. const BottomBar = document.createElement('div');
  282. BottomBar.className = 'BottomBar';
  283. popupContainer.appendChild(BottomBar);
  284. const TopBar = document.createElement('div');
  285. TopBar.className = 'TopBar';
  286. popupContainer.appendChild(TopBar);
  287. const RightBar = document.createElement('div');
  288. RightBar.className = 'RightBar';
  289. popupContainer.appendChild(RightBar);
  290. const LeftBar = document.createElement('div');
  291. LeftBar.className = 'LeftBar';
  292. popupContainer.appendChild(LeftBar);
  293.  
  294. const TR = document.createElement('div');
  295. TR.className = 'CornerBox TR';
  296. popupContainer.appendChild(TR);
  297. const TL = document.createElement('div');
  298. TL.className = 'CornerBox TL';
  299. popupContainer.appendChild(TL);
  300. const BR = document.createElement('div');
  301. BR.className = 'CornerBox BR';
  302. popupContainer.appendChild(BR);
  303. const BL = document.createElement('div');
  304. BL.className = 'CornerBox BL';
  305. popupContainer.appendChild(BL);
  306.  
  307. const centerBox = document.createElement('div');
  308. centerBox.className = 'popup centerBox';
  309. popupContainer.appendChild(centerBox);
  310.  
  311. const style2 = document.createElement('style');
  312. style2.type = 'text/css';
  313. document.head.appendChild(style2);
  314.  
  315.  
  316.  
  317. //-------------------------------------------------------------------------
  318.  
  319. // Variable
  320. const ZOOM_SPEED = 0.005;
  321. let pageDirection;
  322. let isLockedY = false;
  323. let isLockedX = false;
  324. let scale = 1;
  325. let clickTimeout;
  326. let popupTimer;
  327. let isScale, isScaleTR, isScaleBR, isScaleTL, isScaleBL;
  328. let rect, rectT, rectH, rectL, rectW;
  329. let rectIH, rectIW, rectIT, rectIL, rectIRatio;
  330. let rectzT, rectzH, rectzL, rectzW, rectzRatio;
  331. let scaleCurrentX, scaleCurrentY;
  332. let scaleFactorX, scaleFactorY;
  333. let offsetX, offsetY, offsetXR, offsetYT, offsetXL, offsetYB;
  334. let offsetRatioY, offsetRatioX;
  335. let ishidePopupEnabled = true;
  336. let ScaleMode2 = false;
  337. let imgElementsList = [];
  338. let currentZeroImgElement;
  339. let rectIzRatio;
  340.  
  341. function NoMode() {
  342. isLockedY = false;
  343. isLockedX = false;
  344. isScale = false;
  345. isScaleTR = false;
  346. isScaleTL = false;
  347. isScaleBL = false;
  348. isScaleBR = false;
  349. popupContainer.style.border = '';
  350. TR.style.border = '';
  351. BR.style.border = '';
  352. TL.style.border = '';
  353. BL.style.border = '';
  354. }
  355.  
  356. function LockedYMode() {
  357. NoMode();
  358. isLockedY = true;
  359. popupContainer.style.borderLeft = '6px solid #00ff00';
  360. popupContainer.style.borderRight = '6px solid #00ff00';
  361. LeftBar.style.opacity = '0';
  362. RightBar.style.opacity = '0';
  363. LeftBar.style.display = '';
  364. RightBar.style.display = '';
  365. }
  366. function LockedXMode() {
  367. NoMode();
  368. LockedScreen();
  369. isLockedX = true;
  370. popupContainer.style.borderTop = '6px solid #00ff00';
  371. popupContainer.style.borderBottom = '6px solid #00ff00';
  372. LeftBar.style.opacity = '1';
  373. RightBar.style.opacity = '1';
  374. style2.innerHTML = `.LeftBar::before, .LeftBar::after, .RightBar::before, .RightBar::after { display:block; }`;
  375. }
  376.  
  377. function toggleLockedScreen(event) {
  378. ishidePopupEnabled = !ishidePopupEnabled;
  379. popupContainer.style.outline = ishidePopupEnabled ? '' : '6px solid #ae0001';
  380. }
  381.  
  382. function LockedScreen() {
  383. ishidePopupEnabled = false;
  384. popupContainer.style.outline = '6px solid #ae0001';
  385. }
  386.  
  387. function ScalingMode1() {
  388. TL.style.borderTop = '6px solid #0000ff';
  389. TR.style.borderTop = '6px solid #0000ff';
  390. TL.style.borderLeft = '6px solid #0000ff';
  391. BL.style.borderLeft = '6px solid #0000ff';
  392. TR.style.borderRight = '6px solid #0000ff';
  393. BR.style.borderRight = '6px solid #0000ff';
  394. BR.style.borderBottom = '6px solid #0000ff';
  395. BL.style.borderBottom = '6px solid #0000ff';
  396. }
  397. function ScalingMode2() {
  398. ScalingMode1();
  399. TL.style.borderColor = '#ff00ff';
  400. TR.style.borderColor = '#ff00ff';
  401. BL.style.borderColor = '#ff00ff';
  402. BR.style.borderColor = '#ff00ff';
  403. }
  404. function ScalingMode0() {
  405. TL.style.border = '';
  406. TR.style.border = '';
  407. BL.style.border = '';
  408. BR.style.border = '';
  409. }
  410.  
  411. function ResetGeometry() {
  412. let rectF = popup.getBoundingClientRect();
  413. rectzH = rectF.height;
  414. rectzW = rectF.width;
  415. rectzT = rectF.top;
  416. rectzL = rectF.left;
  417. popup.style.maxHeight = rectzH + 'px';
  418. popup.style.height = rectzH + 'px';
  419. popup.style.width = rectzW + 'px';
  420. popupContainer.style.top = rectzT + (rectzH / 2) + 'px';
  421. popupContainer.style.left = rectzL + (rectzW / 2) + 'px';
  422. popupContainer.style.transformOrigin = '50% 50% 0px';
  423. popupContainer.style.transform = `translate(-50%, -50%) scaleX(1) scaleY(1)`;
  424. }
  425.  
  426. function BarClear() {
  427. TL.style.border = '';
  428. TR.style.border = '';
  429. BL.style.border = '';
  430. BR.style.border = '';
  431. TL.style.background = '';
  432. TR.style.background = '';
  433. BL.style.background = '';
  434. BR.style.background = '';
  435. TopBar.style.background = '';
  436. LeftBar.style.background = '';
  437. RightBar.style.background = '';
  438. BottomBar.style.background = '';
  439. popupContainer.style.border = '';
  440. LeftBar.style.opacity = '0';
  441. RightBar.style.opacity = '0';
  442. }
  443.  
  444.  
  445. const loadingIcon = document.createElement('div');
  446.  
  447. function NavigateAlbum() {
  448. let pair = albumSelector.find(pair => currentZeroImgElement.matches(pair.imgElement));
  449. if (pair) {
  450. let ancestorElement = currentZeroImgElement.closest(pair.albumElements);
  451. if (ancestorElement) {
  452. imgElementsList = Array.from(ancestorElement.querySelectorAll(pair.imgElement));
  453. let zeroIndex = imgElementsList.indexOf(currentZeroImgElement);
  454. let direction = pageDirection;
  455. let newIndex = zeroIndex + direction;
  456. TR.textContent = `${newIndex + 1}/${imgElementsList.length}`;
  457.  
  458.  
  459. document.querySelectorAll('.loadingIcon').forEach(e => e.remove())
  460.  
  461.  
  462. if (newIndex <= 0) {
  463. LeftBar.style.display = 'none';
  464. TR.textContent = `1/${imgElementsList.length}`;
  465. } else {
  466. LeftBar.style.display = '';
  467. }
  468. if (newIndex >= imgElementsList.length - 1) {
  469. RightBar.style.display = 'none';
  470. TR.textContent = `${imgElementsList.length}/${imgElementsList.length}`;
  471. } else {
  472. RightBar.style.display = '';
  473. }
  474. if (newIndex < 0 || newIndex >= imgElementsList.length) {
  475. return;
  476. }
  477.  
  478. const loadingIcon = document.createElement('div');
  479. loadingIcon.className = 'loadingIcon'
  480. popupContainer.appendChild(loadingIcon);
  481. loadingIcon.innerHTML = '⟳';
  482. loadingIcon.style.display = 'none';
  483. loadingIcon.style.transition = 'transform 0.1s linear';
  484. loadingIcon.style.cssText = 'position:absolute; transform:translateZ(0); z-index:9999; font-size:55px; height:40px; width:40px; line-height:40px; top:calc(50% - 20px); left:calc(50% - 20px)';
  485. loadingIcon.style.color = '#0000';;
  486. currentZeroImgElement = imgElementsList[newIndex];
  487. var img = new Image();
  488. function rotateLoadingIcon() {
  489. var angle = parseFloat(loadingIcon.getAttribute('data-angle')) || 0;
  490. angle += 27;
  491. loadingIcon.style.transform = 'rotate(' + angle + 'deg)';
  492. loadingIcon.setAttribute('data-angle', angle);
  493. loadingIcon.style.color = '#777';
  494. }
  495. var rotationInterval = setInterval(rotateLoadingIcon, 100);
  496.  
  497. img.onload = function() {
  498.  
  499. document.querySelectorAll('.loadingIcon').forEach(e => e.remove())
  500. clearInterval(rotationInterval);
  501.  
  502. let natHeight = img.naturalHeight;
  503. let vh = window.innerHeight / 100;
  504. let rect = popup.getBoundingClientRect();
  505. let rectH = rect.height;
  506. if ((natHeight > ((90 * vh) - 10)) || (rectH > ((90 * vh) - 10))) {
  507. popup.style.maxHeight = (90 * vh) - 10 + 'px';
  508. popup.style.width = '';
  509. popupContainer.style.top = '50%';
  510. } else {
  511. popup.style.height = '';
  512. popup.style.maxHeight = 'unset';
  513. }
  514. };
  515.  
  516. img.onerror = function() {
  517. loadingIcon.style.display = 'none';
  518. clearInterval(rotationInterval);
  519. };
  520. loadingIcon.style.display = 'block';
  521.  
  522. popup.src = currentZeroImgElement.src;
  523. img.src = popup.src;
  524. }
  525. }
  526. }
  527.  
  528. // Mouse Click: Center
  529. centerBox.addEventListener('click', function(event) {
  530. if (clickTimeout) clearTimeout(clickTimeout);
  531. clickTimeout = setTimeout(function() {
  532. ResetGeometry();
  533. if (!isScale) {
  534. isLockedY = !isLockedY;
  535. }
  536. if (isLockedY) {
  537. LockedYMode();
  538. let rect = popupContainer.getBoundingClientRect();
  539. offsetX = event.clientX - rect.left - (rect.width / 2);
  540. offsetY = event.clientY - rect.top - (rect.height / 2);
  541. } else {
  542. NoMode();
  543. }
  544. }, 300);
  545. });
  546.  
  547. centerBox.addEventListener('dblclick', function(event) {
  548. clearTimeout(clickTimeout);
  549. toggleLockedScreen();
  550. if (!ishidePopupEnabled) {
  551. backdrop.style.display = 'block';
  552. backdrop.style.zIndex = '999';
  553. backdrop.style.backdropFilter = 'blur(10px)';
  554. }
  555. });
  556. //-------------------------------------------------------------------------
  557.  
  558. // Mouse Click: Corners
  559. document.querySelectorAll('.CornerBox').forEach(element => {
  560. element.addEventListener('click', function(event) {
  561. ishidePopupEnabled = false;
  562. if (isScale) {
  563. BarClear();
  564. isLockedY = false;
  565. isLockedX = false;
  566. popup.style.border = '';
  567.  
  568. const clickedElement = event.target;
  569. const popupContainer = clickedElement.parentElement;
  570. const currentTransform = window.getComputedStyle(popupContainer).transform;
  571. const matrixMatch = currentTransform.match(/^matrix\(([^,]+), [^,]+, [^,]+, ([^,]+), [^,]+, [^,]+\)$/);
  572. if (matrixMatch) {
  573. scaleCurrentX = parseFloat(matrixMatch[1]);
  574. scaleCurrentY = parseFloat(matrixMatch[2]);
  575. }
  576.  
  577. let rect = popupContainer.getBoundingClientRect();
  578. offsetYT = event.clientY - rect.top;
  579. offsetXL = event.clientX - rect.left;
  580. offsetYB = rect.height + rect.top - event.clientY;
  581. offsetXR = rect.width + rect.left - event.clientX;
  582.  
  583. rectT = rect.top;
  584. rectL = rect.left;
  585. rectH = rect.height;
  586. rectW = rect.width;
  587.  
  588. } else {
  589. LockedScreen();
  590. ResetGeometry();
  591. }
  592.  
  593. });
  594. });
  595. document.querySelectorAll('.CornerBox').forEach(element => {
  596. element.addEventListener('click', function(event) {
  597. if (clickTimeout) clearTimeout(clickTimeout);
  598. isScale = !isScale;
  599. }, 300);
  600. });
  601. document.querySelectorAll('.CornerBox').forEach(element => {
  602. element.addEventListener('dblclick', function(event) {
  603. clearTimeout(clickTimeout);
  604. ScaleMode2 = !ScaleMode2;
  605. });
  606. });
  607.  
  608. TL.addEventListener('click', function(event) {
  609. if (clickTimeout) clearTimeout(clickTimeout);
  610. clickTimeout = setTimeout(function() {
  611. isScaleTL = !isScaleTL;
  612. isScaleTR = false;
  613. isScaleBL = false;
  614. isScaleBR = false;
  615. LeftBar.style.display = '';
  616. RightBar.style.display = '';
  617. }, 300);
  618. });
  619. TR.addEventListener('click', function(event) {
  620. if (clickTimeout) clearTimeout(clickTimeout);
  621. clickTimeout = setTimeout(function() {
  622. isScaleTL = false;
  623. isScaleTR = !isScaleTR;
  624. isScaleBL = false;
  625. isScaleBR = false;
  626. LeftBar.style.display = '';
  627. RightBar.style.display = '';
  628. }, 300);
  629. });
  630. BL.addEventListener('click', function(event) {
  631. if (clickTimeout) clearTimeout(clickTimeout);
  632. clickTimeout = setTimeout(function() {
  633. isScaleTL = false;
  634. isScaleTR = false;
  635. isScaleBL = !isScaleBL;
  636. isScaleBR = false;
  637. LeftBar.style.display = '';
  638. RightBar.style.display = '';
  639. }, 300);
  640. });
  641. BR.addEventListener('click', function(event) {
  642. if (clickTimeout) clearTimeout(clickTimeout);
  643. clickTimeout = setTimeout(function() {
  644. isScaleTL = false;
  645. isScaleTR = false;
  646. isScaleBL = false;
  647. isScaleBR = !isScaleBR;
  648. LeftBar.style.display = '';
  649. RightBar.style.display = '';
  650. }, 300);
  651. });
  652. //-------------------------------------------------------------------------
  653.  
  654.  
  655. // Mouse Move: Pan, Scale
  656. document.addEventListener('mousemove', function(event) {
  657. // Panning mode: popup locked and follows the mouse
  658. if (isLockedY) {
  659. popupContainer.style.left = (event.clientX - offsetX) + 'px';
  660. popupContainer.style.top = (event.clientY - offsetY) + 'px';
  661.  
  662. } else if (isScale) {
  663. ScalingMode1();
  664. if (ScaleMode2) {
  665. ScalingMode2();
  666. }
  667.  
  668. if (isScaleTL) {
  669. popupContainer.style.transformOrigin = '100% 100% 0px';
  670. scaleFactorY = scaleCurrentY * (1 + (rectT - event.clientY + offsetYT) / rectH);
  671. scaleFactorX = scaleCurrentX * (1 + (rectL - event.clientX + offsetXL) / rectW);
  672. } else if (isScaleTR) {
  673. popupContainer.style.transformOrigin = '0 100% 0px';
  674. scaleFactorY = scaleCurrentY * (1 + (rectT - event.clientY + offsetYT) / rectH);
  675. scaleFactorX = scaleCurrentX * ((event.clientX - rectL + offsetXR) / rectW);
  676. } else if (isScaleBL) {
  677. popupContainer.style.transformOrigin = '100% 0% 0px';
  678. scaleFactorY = scaleCurrentY * ((event.clientY - rectT + offsetYB) / rectH);
  679. scaleFactorX = scaleCurrentX * (1 + (rectL - event.clientX + offsetXL) / rectW);
  680. } else if (isScaleBR) {
  681. popupContainer.style.transformOrigin = '0% 0% 0px';
  682. scaleFactorY = scaleCurrentY * ((event.clientY - rectT + offsetYB) / rectH);
  683. scaleFactorX = scaleCurrentX * ((event.clientX - rectL + offsetXR) / rectW);
  684. }
  685. if (ScaleMode2) {
  686. popupContainer.style.transform = `translate(-50%, -50%) scaleX(${scaleFactorX}) scaleY(${scaleFactorY})`;
  687.  
  688. } else {
  689. popupContainer.style.transform = `translate(-50%, -50%) scaleX(${scaleFactorX}) scaleY(${scaleFactorX})`;
  690. }
  691. }
  692. });
  693.  
  694.  
  695. // Mouse Wheel: Zoom, Scroll, Navigate
  696. function ZoomOrScroll(event) {
  697. event.preventDefault();
  698. if (isLockedY) {
  699. let deltaY = event.deltaY * -ZOOM_SPEED;
  700. let newTop = parseInt(popupContainer.style.top) || 0;
  701. newTop += deltaY * 100;
  702. popupContainer.style.top = newTop + 'px';
  703. offsetY -= deltaY * 100;
  704.  
  705. } else if (isLockedX && currentZeroImgElement) {
  706. pageDirection = event.deltaY > 0 ? 1 : -1;
  707. NavigateAlbum();
  708.  
  709. if (pageDirection === 1) {
  710. const imageElement = currentContainer.querySelector(imgElements);
  711. specialRightBar.forEach(pair => {
  712. if (imageElement.matches(pair.selector)) {
  713. pair.func(imageElement);
  714. }
  715. });
  716. } else {
  717. const imageElement = currentContainer.querySelector(imgElements);
  718. specialLeftBar.forEach(pair => {
  719. if (imageElement.matches(pair.selector)) {
  720. pair.func(imageElement);
  721. }
  722. });
  723. }
  724.  
  725. } else {
  726. scale += event.deltaY * -ZOOM_SPEED;
  727. scale = Math.min(Math.max(0.125, scale), 10);
  728. popupContainer.style.transform = `translate(-50%, -50%) scaleX(${scale}) scaleY(${scale})`;
  729. }
  730. }
  731. popupContainer.addEventListener('wheel', ZoomOrScroll);
  732. //-------------------------------------------------------------------------
  733.  
  734.  
  735. // Bottom Bar: Album
  736. BottomBar.addEventListener('mouseenter', function(e) {
  737.  
  738. if (isScale) {
  739. return;
  740. } else {
  741. BottomBar.style.opacity = '1';
  742.  
  743. let rect = popup.getBoundingClientRect();
  744. rectzRatio = rect.height / rect.width;
  745. rectIzRatio = Number(rectIRatio.toFixed(3)) / Number(rectzRatio.toFixed(3));
  746.  
  747. if (isAlbum) {
  748. if (!isScale) {
  749. BottomBar.style.background = 'linear-gradient(to right, rgba(0, 0, 255, 0) 0%, rgba(0, 0, 255, 0.5) 25%, rgba(0, 0, 255, 0.5) 75%, rgba(0, 0, 255, 0) 100%)';
  750. }
  751. } else {
  752. BottomBar.style.background = '';
  753. if (!( (rectIzRatio === 1) || isScale ) ) {
  754. style2.innerHTML = `
  755. .BottomBar::after {
  756. display: block;
  757. }
  758. `;
  759. BL.style.background = 'rgba(0, 0, 0, 0.5)';
  760. BR.style.background = 'rgba(0, 0, 0, 0.5)';
  761. BottomBar.style.background = 'rgba(0, 0, 0, 0.5)';
  762. } else {
  763. style2.innerHTML = `
  764. .BottomBar::after {
  765. display: none;
  766. }
  767. `;
  768. }
  769. }
  770. }
  771. });
  772.  
  773. BottomBar.addEventListener('mouseleave', function() {
  774. BottomBar.style.opacity = '0';
  775. if (!isLockedX) {
  776. BarClear();
  777. }
  778. });
  779.  
  780. BottomBar.addEventListener('click', function(event) {
  781. if (clickTimeout) clearTimeout(clickTimeout);
  782. clickTimeout = setTimeout(function() {
  783. if (!isScale) {
  784. LeftBar.style.opacity = '0';
  785. RightBar.style.opacity = '0';
  786. }
  787. if (isAlbum) {
  788. ResetGeometry();
  789. var img = new Image();
  790. img.onload = function() {
  791. natHeight = img.naturalHeight;
  792. natWidth = img.naturalWidth;
  793. };
  794. img.src = popup.src
  795. rectIRatio = natHeight / natWidth;
  796. isLockedX = !isLockedX;
  797. if (isLockedX) {
  798. LockedXMode();
  799. LeftBar.style.opacity = '1';
  800. RightBar.style.opacity = '1';
  801. } else {
  802. popupContainer.style.border = '';
  803. LeftBar.style.display = '';
  804. RightBar.style.display = '';
  805. }
  806. let pair = albumSelector.find(pair => currentZeroImgElement.matches(pair.imgElement));
  807. if (pair) {
  808. let ancestorElement = currentZeroImgElement.closest(pair.albumElements);
  809. if (ancestorElement) {
  810. imgElementsList = Array.from(ancestorElement.querySelectorAll(pair.imgElement));
  811. let zeroIndex = imgElementsList.indexOf(currentZeroImgElement);
  812. if (zeroIndex <= 0) {
  813. LeftBar.style.display = 'none';
  814. } else {
  815. LeftBar.style.display = '';
  816. }
  817. if (zeroIndex >= imgElementsList.length - 1) {
  818. RightBar.style.display = 'none';
  819. } else {
  820. RightBar.style.display = '';
  821. }
  822. }
  823. }
  824. } else {
  825. ResetGeometry();
  826. if (isScale) {
  827. isScale = false;
  828. popup.style.maxHeight = rectzH + 'px';
  829. popup.style.height = rectzH + 'px';
  830. offsetRatioY = 0;
  831. } else {
  832. popup.style.maxHeight = 'unset';
  833. popup.style.height = '';
  834. offsetRatioY = (rectzH - rectzW * rectIRatio) / 2 ;
  835. }
  836. popupContainer.style.top = rectzT + (rectzH / 2) + offsetRatioY + 'px';
  837. }
  838. }, 300);
  839. });
  840.  
  841. BottomBar.addEventListener('dblclick', function(event) {
  842. clearTimeout(clickTimeout);
  843. if (isAlbum) {
  844. ResetGeometry();
  845. var img = new Image();
  846. img.onload = function() {
  847. natHeight = img.naturalHeight;
  848. natWidth = img.naturalWidth;
  849. };
  850. img.src = popup.src
  851. rectIRatio = natHeight / natWidth;
  852. if (isScale) {
  853. popup.style.maxHeight = rectzH + 'px';
  854. popup.style.height = rectzH + 'px';
  855. offsetRatioY = 0;
  856. } else {
  857. popup.style.maxHeight = 'unset';
  858. popup.style.height = '';
  859. offsetRatioY = (rectzH - rectzW * rectIRatio) / 2 ;
  860. }
  861. popupContainer.style.top = rectzT + (rectzH / 2) + offsetRatioY + 'px';
  862. BarClear();
  863. } else {
  864. return;
  865. }
  866. });
  867. //-------------------------------------------------------------------------
  868.  
  869.  
  870. // Indicators
  871. document.querySelectorAll('.CornerBox').forEach(element => {
  872. element.addEventListener('mouseenter', function(event) {
  873. ScalingMode1();
  874. if (ScaleMode2) {
  875. ScalingMode2();
  876. }
  877. });
  878. element.addEventListener('mouseleave', function(event) {
  879. if (!isScale) {
  880. ScalingMode0();
  881. }
  882. });
  883. });
  884.  
  885. // Re-scale/ Navigate
  886. TopBar.addEventListener('click', function(event) {
  887. if (clickTimeout) clearTimeout(clickTimeout);
  888. clickTimeout = setTimeout(function() {
  889. ResetGeometry();
  890. if (isAlbum) {
  891. var img = new Image();
  892. img.onload = function() {
  893. natHeight = img.naturalHeight;
  894. natWidth = img.naturalWidth;
  895. };
  896. img.src = popup.src
  897. rectIRatio = natHeight / natWidth;
  898. }
  899. if (isScale) {
  900. isScale = false;
  901. popup.style.maxHeight = rectzH + 'px';
  902. popup.style.height = rectzH + 'px';
  903. offsetRatioY = 0;
  904. } else {
  905. popup.style.maxHeight = 'unset';
  906. popup.style.height = '';
  907. offsetRatioY = (rectzH - rectzW * rectIRatio) / 2 ;
  908. }
  909. popupContainer.style.top = rectzT + (rectzH / 2) - offsetRatioY + 'px';
  910. BarClear();
  911.  
  912. }, 300);
  913. });
  914.  
  915. const styleCrop = document.createElement('style');
  916. styleCrop.type = 'text/css';
  917. styleCrop.innerHTML = `.cropArea1,.cropArea2,.cropArea3,.cropArea4 { display:none; }`;
  918. const CropCover = document.createElement('div');
  919. const cropArea1 = document.createElement('div');
  920. const cropArea2 = document.createElement('div');
  921. const cropArea3 = document.createElement('div');
  922. const cropArea4 = document.createElement('div');
  923.  
  924. let clickX1, clickY1, clickX2, clickY2;
  925. let clickCount;
  926. let cropAreaSet = false;
  927.  
  928. TopBar.addEventListener('dblclick', function(event) {
  929. clearTimeout(window.clickTimeout);
  930.  
  931. LockedScreen();
  932. clickCount = 0;
  933. ResetGeometry()
  934. cropAreaSet = false;
  935.  
  936. const CropCover = document.createElement('div');
  937. const cropArea1 = document.createElement('div');
  938. const cropArea2 = document.createElement('div');
  939. const cropArea3 = document.createElement('div');
  940. const cropArea4 = document.createElement('div');
  941. CropCover.className = 'CropCover'
  942. cropArea1.className = 'cropArea1';
  943. cropArea2.className = 'cropArea2';
  944. cropArea3.className = 'cropArea3';
  945. cropArea4.className = 'cropArea4';
  946. popupContainer.appendChild(CropCover);
  947. document.body.appendChild(cropArea1);
  948. document.body.appendChild(cropArea2);
  949. document.body.appendChild(cropArea3);
  950. document.body.appendChild(cropArea4);
  951. CropCover.style.cssText = 'position:absolute; transform:translateZ(0); top:0; left:0; box-sizing:border-box; height:100%; width:100%; z-index:99999; border:1px solid yellow;';
  952. cropArea1.style.cssText ='display: block; z-index: 9999; position: fixed; background: rgba(0, 0, 0, 0.4);';
  953. cropArea2.style.cssText ='display: block; z-index: 9999; position: fixed; background: rgba(0, 0, 0, 0.4);';
  954. cropArea3.style.cssText ='display: block; z-index: 9999; position: fixed; background: rgba(0, 0, 0, 0.4);';
  955. cropArea4.style.cssText ='display: block; z-index: 9999; position: fixed; background: rgba(0, 0, 0, 0.4);';
  956.  
  957. let rect = popup.getBoundingClientRect();
  958. rectzH = rect.height;
  959. rectzW = rect.width;
  960. rectzT = rect.top;
  961. rectzL = rect.left;
  962.  
  963. let clickTimeout;
  964.  
  965. CropCover.addEventListener('click', function(e) {
  966. if (clickCount === 0) {
  967. clickX1 = e.clientX;
  968. clickY1 = e.clientY;
  969. clickCount = 1;
  970. } else if (clickCount === 1) {
  971. clickCount = 2;
  972. clickX2 = e.clientX;
  973. clickY2 = e.clientY;
  974. cropAreaSet = true;
  975. if (clickCount === 2) {
  976. cropImage();
  977. }
  978. }
  979. });
  980.  
  981. document.addEventListener('mousemove', function(event) {
  982.  
  983. cropArea1.style.left = '0px';
  984. cropArea1.style.top = '0px';
  985. cropArea1.style.height = '100vh';
  986.  
  987. cropArea2.style.top = '0px';
  988.  
  989.  
  990. if (clickCount === 0) {
  991. cropArea1.style.width = event.clientX + 'px';
  992.  
  993. cropArea2.style.left = event.clientX + 'px';
  994. cropArea2.style.height = event.clientY + 'px';
  995. cropArea2.style.width = `calc(100vw - ${event.clientX}px)`;
  996.  
  997.  
  998. } else if (clickCount === 1) {
  999. cropArea1.style.width = clickX1 + 'px';
  1000.  
  1001. cropArea2.style.left = clickX1 + 'px';
  1002. cropArea2.style.height = clickY1 + 'px';
  1003. cropArea2.style.width = `calc(100vw - ${clickX1}px)`;
  1004.  
  1005.  
  1006. }
  1007. if (!cropAreaSet && (clickCount === 1)) {
  1008. cropArea3.style.left = clickX1 + 'px';
  1009. cropArea3.style.top = event.clientY + 1 + 'px';
  1010. cropArea3.style.width = `calc(${event.clientX}px + 1px - ${clickX1}px)`;
  1011. cropArea3.style.height = `calc(100vh - 1px - ${event.clientY}px)`;
  1012.  
  1013. cropArea4.style.left = event.clientX + 1 + 'px';
  1014. cropArea4.style.top = clickY1 + 'px'
  1015. cropArea4.style.height = `calc(100vh - 1px - ${clickY1}px)`;
  1016. cropArea4.style.width = `calc(100vw - 1px - ${event.clientX}px)`;
  1017.  
  1018.  
  1019. }
  1020. });
  1021.  
  1022. });
  1023.  
  1024. function cropImage() {
  1025. var canvas = document.createElement('canvas');
  1026. canvas.id = 'cropCanvas';
  1027. var ctx = canvas.getContext('2d');
  1028. document.body.appendChild(canvas);
  1029. let cropX, cropY, cropW, cropH, scW, scH
  1030.  
  1031. scW = clickX2 - clickX1
  1032. scH = clickY2 - clickY1
  1033. cropX = natWidth * ((clickX1 - rectzL) / rectzW);
  1034. cropY = natHeight * ((clickY1 - rectzT) / rectzH);
  1035. cropW = natWidth * (scW / rectzW);
  1036. cropH = natHeight * (scH / rectzH);
  1037. canvas.width = scW;
  1038. canvas.height = scH;
  1039.  
  1040. var image = new Image();
  1041. image.crossOrigin = "anonymous";
  1042. image.src = popup.src
  1043. image.onload = function() {
  1044. ctx.drawImage(image, cropX, cropY, cropW, cropH, 0, 0, scW, scH);
  1045. saveImage(canvas);
  1046. }
  1047.  
  1048. document.querySelectorAll('.CropCover').forEach(e => e.remove())
  1049. }
  1050.  
  1051. function saveImage(canvas) {
  1052. if (confirm('Do you want to save the image?')) {
  1053. var croppedImageDataURL = canvas.toDataURL('image/png');
  1054. var originalFileName = popup.src.split('/').pop();
  1055. var truncatedFileName = originalFileName.length > 100 ? originalFileName.substring(0, 100) : originalFileName;
  1056. var downloadLink = document.createElement('a');
  1057. downloadLink.href = croppedImageDataURL;
  1058. downloadLink.download = truncatedFileName;
  1059. document.body.appendChild(downloadLink);
  1060. downloadLink.click();
  1061. }
  1062.  
  1063. clickCount = 0;
  1064. cropAreaSet = false;
  1065. document.querySelectorAll('.cropArea1').forEach(e => e.remove())
  1066. document.querySelectorAll('.cropArea2').forEach(e => e.remove())
  1067. document.querySelectorAll('.cropArea3').forEach(e => e.remove())
  1068. document.querySelectorAll('.cropArea4').forEach(e => e.remove())
  1069. document.body.removeChild(downloadLink);
  1070. var removecropCanvas = document.getElementById('cropCanvas');
  1071. removecropCanvas.remove();
  1072.  
  1073. }
  1074.  
  1075.  
  1076. let zeroIndex;
  1077. LeftBar.addEventListener('click', function(event) {
  1078. if (clickTimeout) clearTimeout(clickTimeout);
  1079. clickTimeout = setTimeout(function() {
  1080. ResetGeometry();
  1081. if (isAlbum) {
  1082. var img = new Image();
  1083. img.onload = function() {
  1084. natHeight = img.naturalHeight;
  1085. natWidth = img.naturalWidth;
  1086. };
  1087. img.src = popup.src
  1088. rectIRatio = natHeight / natWidth;
  1089. }
  1090. if (isScale) {
  1091. isScale = false;
  1092. popup.style.width = rectzW + 'px';
  1093. offsetRatioX = 0;
  1094. } else {
  1095. popup.style.width = '';
  1096. offsetRatioX = (rectzW - (rectzH / rectIRatio)) / 2 ;
  1097. }
  1098. if (isLockedX && currentZeroImgElement) {
  1099. pageDirection = -1;
  1100. NavigateAlbum();
  1101. TL.style.background = 'rgba(0, 0, 0, 0.5)';
  1102. BL.style.background = 'rgba(0, 0, 0, 0.5)';
  1103. LeftBar.style.background = 'rgba(0, 0, 0, 0.5)';
  1104.  
  1105. const imageElement = currentContainer.querySelector(imgElements);
  1106. specialLeftBar.forEach(pair => {
  1107. if (imageElement.matches(pair.selector)) {
  1108. pair.func(imageElement);
  1109. }
  1110. });
  1111. } else {
  1112. popupContainer.style.left = rectzL + (rectzW / 2) - offsetRatioX + 'px';
  1113. }
  1114. }, 300);
  1115. });
  1116. RightBar.addEventListener('click', function(event) {
  1117. if (clickTimeout) clearTimeout(clickTimeout);
  1118. clickTimeout = setTimeout(function() {
  1119. ResetGeometry();
  1120. if (isAlbum) {
  1121. var img = new Image();
  1122. img.onload = function() {
  1123. natHeight = img.naturalHeight;
  1124. natWidth = img.naturalWidth;
  1125. };
  1126. img.src = popup.src
  1127. rectIRatio = natHeight / natWidth;
  1128. }
  1129. if (isScale) {
  1130. isScale = false;
  1131. popup.style.width = rectzW + 'px';
  1132. offsetRatioX = 0;
  1133. } else {
  1134. popup.style.width = '';
  1135. offsetRatioX = (rectzW - (rectzH / rectIRatio)) / 2 ;
  1136. }
  1137. if (isLockedX && currentZeroImgElement) {
  1138. pageDirection = 1;
  1139. NavigateAlbum();
  1140. TR.style.background = 'rgba(0, 0, 0, 0.5)';
  1141. BR.style.background = 'rgba(0, 0, 0, 0.5)';
  1142. RightBar.style.background = 'rgba(0, 0, 0, 0.5)';
  1143.  
  1144. const imageElement = currentContainer.querySelector(imgElements);
  1145. specialRightBar.forEach(pair => {
  1146. if (imageElement.matches(pair.selector)) {
  1147. pair.func(imageElement);
  1148. }
  1149. });
  1150. } else {
  1151. popupContainer.style.left = rectzL + (rectzW / 2) + offsetRatioX + 'px';
  1152. }
  1153. }, 300);
  1154. });
  1155.  
  1156. TopBar.addEventListener('mouseenter', function() {
  1157.  
  1158. var img = new Image();
  1159. img.onload = function() {
  1160. natHeight = img.naturalHeight;
  1161. natWidth = img.naturalWidth;
  1162. };
  1163. img.src = popup.src
  1164. let rectZ = popup.getBoundingClientRect();
  1165. let rectZH = rectZ.height;
  1166. let rectZW = rectZ.width;
  1167. let rectZRatio = rectZH / rectZW;
  1168. let natRatio = natHeight / natWidth;
  1169. let rectNZRatio = Number(natRatio.toFixed(3)) / Number(rectZRatio.toFixed(3));
  1170. // not original Ratio and not scaling mode aplly with arrow indicator
  1171. if (!((rectNZRatio === 1) || isScale )) {
  1172.  
  1173. TopBar.style.opacity = '1';
  1174. TL.style.background = 'rgba(0, 0, 0, 0.5)';
  1175. TR.style.background = 'rgba(0, 0, 0, 0.5)';
  1176. TopBar.style.background = 'rgba(0, 0, 0, 0.5)';
  1177.  
  1178. style2.innerHTML = `.TopBar::after { display: block; }`;
  1179.  
  1180. } else {
  1181. style2.innerHTML = `.TopBar::after { display: none; }`;
  1182. }
  1183. });
  1184. LeftBar.addEventListener('mouseenter', function() {
  1185. LeftBar.style.opacity = '1';
  1186. let rect = popup.getBoundingClientRect();
  1187. rectzRatio = rect.height / rect.width;
  1188. rectIzRatio = Number(rectIRatio.toFixed(3)) / Number(rectzRatio.toFixed(3));
  1189. if ( isLockedX || !( (rectIzRatio === 1) || isScale ) ) {
  1190. style2.innerHTML = `
  1191. .LeftBar::before, .LeftBar::after {
  1192. display: block;
  1193. }`;
  1194. TL.style.background = 'rgba(0, 0, 0, 0.5)';
  1195. BL.style.background = 'rgba(0, 0, 0, 0.5)';
  1196. LeftBar.style.background = 'rgba(0, 0, 0, 0.5)';
  1197. } else {
  1198. style2.innerHTML = `
  1199. .LeftBar::before, .LeftBar::after {
  1200. display: none;
  1201. }`;
  1202. }
  1203. });
  1204. RightBar.addEventListener('mouseenter', function() {
  1205. RightBar.style.opacity = '1';
  1206. let rect = popup.getBoundingClientRect();
  1207. rectzRatio = rect.height / rect.width;
  1208. rectIzRatio = Number(rectIRatio.toFixed(3)) / Number(rectzRatio.toFixed(3));
  1209. if ( isLockedX || !( (rectIzRatio === 1) || isScale ) ) {
  1210. style2.innerHTML = `
  1211. .RightBar::before, .RightBar::after {
  1212. display: block;
  1213. }`;
  1214. TR.style.background = 'rgba(0, 0, 0, 0.5)';
  1215. BR.style.background = 'rgba(0, 0, 0, 0.5)';
  1216. RightBar.style.background = 'rgba(0, 0, 0, 0.5)';
  1217. } else {
  1218. style2.innerHTML = `
  1219. .RightBar::before, .RightBar::after {
  1220. display: none;
  1221. }`;
  1222. }
  1223. });
  1224.  
  1225. TopBar.addEventListener('mouseleave', function() {
  1226. TopBar.style.opacity = '0';
  1227. TL.style.background = '';
  1228. TR.style.background = '';
  1229. });
  1230. LeftBar.addEventListener('mouseleave', function() {
  1231. if (isLockedX) {
  1232. LeftBar.style.opacity = '1';
  1233. } else {
  1234. LeftBar.style.opacity = '0';
  1235. }
  1236. TL.style.background = '';
  1237. BL.style.background = '';
  1238. LeftBar.style.background = '';
  1239. });
  1240. RightBar.addEventListener('mouseleave', function() {
  1241. if (isLockedX) {
  1242. RightBar.style.opacity = '1';
  1243. } else {
  1244. RightBar.style.opacity = '0';
  1245. }
  1246. TR.style.background = '';
  1247. BR.style.background = '';
  1248. RightBar.style.background = '';
  1249. });
  1250. //-------------------------------------------------------------------------
  1251.  
  1252. let natXratio, natYratio, natHeight, natWidth;
  1253.  
  1254. // show popup
  1255. function showPopup(src, mouseX, mouseY) {
  1256. console.log('isshowPopupEnabled:', isshowPopupEnabled);
  1257. if (!isshowPopupEnabled) return;
  1258. if (enableP === 0) return;
  1259.  
  1260. ishidePopupEnabled = true;
  1261.  
  1262. popup.src = src;
  1263. popup.style.display = 'block';
  1264. popupContainer.style.display = 'block';
  1265. popupContainer.style.position = 'fixed';
  1266. popupContainer.style.transform = 'translate(-50%, -50%) scaleX(1) scaleY(1)';
  1267. backdrop.style.display = 'block';
  1268. backdrop.style.zIndex = '999';
  1269. backdrop.style.backdropFilter = 'blur(10px)';
  1270.  
  1271. if (positionP === 'center') {
  1272. popupContainer.style.top = '50%';
  1273. popupContainer.style.left = '50%';
  1274. } else {
  1275. popupContainer.style.top = `${mouseY}px`;
  1276. popupContainer.style.left = `${mouseX}px`;
  1277. }
  1278.  
  1279. let rectI = popup.getBoundingClientRect();
  1280. rectIH = rectI.height;
  1281. rectIW = rectI.width;
  1282. rectIT = rectI.top;
  1283. rectIL = rectI.left;
  1284.  
  1285. var img = new Image();
  1286. img.onload = function() {
  1287. natHeight = img.naturalHeight;
  1288. natWidth = img.naturalWidth;
  1289. };
  1290. img.src = popup.src
  1291.  
  1292. natXratio = natWidth / rectIW;
  1293. natYratio = natHeight / rectIH;
  1294. rectIRatio = rectIH / rectIW;
  1295.  
  1296. if (positionP === '') {
  1297. if (mouseY < window.innerHeight * 0.33) {
  1298. popupContainer.style.top = mouseY + (rectIH / 2) - 40 + 'px';
  1299. } else if (mouseY >= window.innerHeight * 0.33 && mouseY < window.innerHeight * 0.67) {
  1300. popupContainer.style.top = mouseY + 'px';
  1301. } else if (mouseY >= window.innerHeight * 0.67) {
  1302. popupContainer.style.top = mouseY - (rectIH / 2) + 40 + 'px';
  1303. }
  1304. if (mouseX < window.innerWidth * 0.33) {
  1305. popupContainer.style.left = mouseX + (rectIW / 2) - 40 + 'px';
  1306. } else if (mouseX >= window.innerWidth * 0.33 && mouseX < window.innerWidth * 0.67) {
  1307. popupContainer.style.left = mouseX + 'px';
  1308. } else if (mouseX >= window.innerWidth * 0.67) {
  1309. popupContainer.style.left = mouseX - (rectIW / 2) + 40 + 'px';
  1310. }
  1311. }
  1312. if (isAlbum) {
  1313. LockedXMode();
  1314. }
  1315.  
  1316. }
  1317.  
  1318. let isAlbum;
  1319. let currentContainer;
  1320. document.addEventListener('mouseover', function(e) {
  1321. if (popupTimer) return;
  1322.  
  1323. let target = e.target.closest(imgContainers);
  1324. let relatedTarget = event.relatedTarget;
  1325.  
  1326. if (target.querySelector(nopeElements)) return;
  1327. currentContainer = target;
  1328. const imageElement = currentContainer.querySelector(imgElements);
  1329. specialElements.forEach(pair => {
  1330. if (imageElement.matches(pair.selector)) {
  1331. pair.func(imageElement);
  1332. }
  1333. });
  1334. if (imageElement) {
  1335. currentZeroImgElement = imageElement;
  1336. if (currentZeroImgElement) {
  1337. let pair = albumSelector.find(pair => currentZeroImgElement.matches(pair.imgElement));
  1338. if (pair) {
  1339. let closestAlbumElement = currentZeroImgElement.closest(pair.albumElements);
  1340. isAlbum = closestAlbumElement && closestAlbumElement.querySelectorAll(pair.imgElement).length > 1;
  1341. if (isAlbum) {
  1342. imgElementsList = Array.from(closestAlbumElement.querySelectorAll(pair.imgElement));
  1343. let zeroIndex = imgElementsList.indexOf(currentZeroImgElement);
  1344. TR.textContent = `${zeroIndex + 1}/${imgElementsList.length}`;
  1345. if (zeroIndex === 0) {
  1346. LeftBar.style.display = 'none';
  1347. } else {
  1348. LeftBar.style.display = '';
  1349. }
  1350. if (zeroIndex === imgElementsList.length - 1) {
  1351. RightBar.style.display = 'none';
  1352. } else {
  1353. RightBar.style.display = '';
  1354. }
  1355. }
  1356. } else {
  1357. isAlbum = false;
  1358. TR.textContent = '';
  1359. LeftBar.style.display = '';
  1360. RightBar.style.display = '';
  1361. }
  1362. }
  1363. if (intervalP === '') {
  1364. showPopup(imageElement.src, e.clientX, e.clientY);
  1365. } else {
  1366. popupTimer = setTimeout(() => {
  1367. showPopup(imageElement.src, e.clientX, e.clientY);
  1368. popupTimer = null;
  1369. }, parseInt(intervalP));
  1370. }
  1371. }
  1372. });
  1373. //-------------------------------------------------------------------------
  1374.  
  1375. // hide popup
  1376. function hidePopup() {
  1377.  
  1378. isshowPopupEnabled = true;
  1379. if (!ishidePopupEnabled) return;
  1380. imgElementsList = [];
  1381. if (popupTimer) {
  1382. clearTimeout(popupTimer);
  1383. }
  1384. popup.style.display = 'none';
  1385. popupContainer.style.display = 'none';
  1386.  
  1387. NoMode();
  1388. popup.style.maxHeight = 'calc(90vh - 10px)';
  1389. popup.style.width = '';
  1390. popup.style.height = '';
  1391. popupContainer.style.left = '50%';
  1392. popupContainer.style.top = '50%';
  1393. popupContainer.style.position = 'fixed';
  1394. popupContainer.style.transform = 'translate(-50%, -50%) scaleX(1) scaleY(1)';
  1395. popupContainer.style.transformOrigin = '';
  1396. popupContainer.style.outline = '';
  1397. backdrop.style.zIndex = '';
  1398. backdrop.style.display = 'none';
  1399. backdrop.style.backdropFilter = '';
  1400. LeftBar.style.opacity = '0';
  1401. RightBar.style.opacity = '0';
  1402. style2.innerHTML = `
  1403. .LeftBar::before,
  1404. .LeftBar::after,
  1405. .RighttBar::before,
  1406. .RighttBar::after {
  1407. display: none;
  1408. }`;
  1409. document.querySelectorAll('.specialElement').forEach(e => e.remove());
  1410.  
  1411. clickCount = 0;
  1412. cropAreaSet = false;
  1413. CropCover.style.zIndex = '1';
  1414. CropCover.style.border = '';
  1415. document.querySelectorAll('.cropArea1').forEach(e => e.remove())
  1416. document.querySelectorAll('.cropArea2').forEach(e => e.remove())
  1417. document.querySelectorAll('.cropArea3').forEach(e => e.remove())
  1418. document.querySelectorAll('.cropArea4').forEach(e => e.remove())
  1419.  
  1420. var removecropCanvas = document.getElementById('cropCanvas');
  1421. removecropCanvas.remove();
  1422. CropCover.remove();
  1423.  
  1424. }
  1425.  
  1426. popupContainer.addEventListener('mouseout', function(event) {
  1427. let relatedTarget = event.relatedTarget;
  1428. if (relatedTarget && (popupContainer.contains(relatedTarget) || relatedTarget.matches('.imgContainers'))) {
  1429. return;
  1430. }
  1431.  
  1432. document.querySelectorAll('.specialElement').forEach(e => e.remove());
  1433. hidePopup();
  1434.  
  1435. if (intervalP !== '') {
  1436. popupTimer = setTimeout(() => {
  1437. popupTimer = null;
  1438. }, parseInt(intervalP));
  1439. }
  1440. });
  1441.  
  1442. //-------------------------------------------------------------------------
  1443.  
  1444.  
  1445. // lock popup in screen
  1446. backdrop.addEventListener('dblclick', function(event) {
  1447. clearTimeout(clickTimeout);
  1448. ishidePopupEnabled = true;
  1449. hidePopup();
  1450. });
  1451. backdrop.addEventListener('click', function(event) {
  1452. if (clickTimeout) clearTimeout(clickTimeout);
  1453. clickTimeout = setTimeout(function() {
  1454. ResetGeometry();
  1455. if (isScale) {
  1456. isScale = false;
  1457. isScaleTL = false;
  1458. isScaleTR = false;
  1459. isScaleBL = false;
  1460. isScaleBR = false;
  1461. ScalingMode0();
  1462.  
  1463. } else if (isLockedY) {
  1464. isLockedY = false;
  1465. popupContainer.style.border = '';
  1466. } else {
  1467. backdrop.style.zIndex = '';
  1468. backdrop.style.display = 'none';
  1469. backdrop.style.backdropFilter = '';
  1470. isshowPopupEnabled = false;
  1471. }
  1472. }, 300);
  1473. });
  1474.  
  1475. }
  1476. //-------------------------------------------------------------------------
  1477.  
  1478.  
  1479. // Is to be run -----------------------------------------------------------
  1480. if (URLmatched) {
  1481. const indicatorBar = document.createElement('div');
  1482. indicatorBar.style.cssText = `
  1483. position: fixed;
  1484. bottom: 0;
  1485. left: 50%;
  1486. transform: translateX(-50%);
  1487. z-index: 9999;
  1488. height: 30px;
  1489. width: 50vw;
  1490. background: #0000;`;
  1491. document.body.appendChild(indicatorBar);
  1492.  
  1493. function toggleIndicator() {
  1494. enableP = 1 - enableP;
  1495.  
  1496. indicatorBar.style.background = enableP ? 'linear-gradient(to right, rgba(50, 190, 152, 0) 0%, rgba(50, 190, 152, 0.5) 25%, rgba(50, 190, 152, 0.5) 75%, rgba(50, 190, 152, 0) 100%)' : 'linear-gradient(to right, rgba(174, 0, 1, 0) 0%, rgba(174, 0, 1, 0.5) 25%, rgba(174, 0, 1, 0.5) 75%, rgba(174, 0, 1, 0) 100%)';
  1497. setTimeout(() => {
  1498. indicatorBar.style.background = '#0000';
  1499. }, 1000);
  1500. if (enableP === 1) {
  1501. HoverZoomMinus();
  1502. } else {
  1503. document.querySelectorAll('.popup-container').forEach(e => e.remove());
  1504. document.querySelectorAll('.popup-backdrop').forEach(e => e.remove());
  1505. document.querySelectorAll('.specialElement').forEach(e => e.remove());
  1506. }
  1507. }
  1508. let hoverTimeout;
  1509. indicatorBar.addEventListener('mouseenter', () => {
  1510. hoverTimeout = setTimeout(toggleIndicator, 500);
  1511. });
  1512. indicatorBar.addEventListener('mouseleave', () => {
  1513. clearTimeout(hoverTimeout);
  1514. indicatorBar.style.background = '#0000';
  1515. });
  1516. if (enableP === 1) {
  1517. HoverZoomMinus();
  1518. }
  1519. } else {
  1520. return;
  1521. }
  1522.  
  1523. })();