🏠 Home 

FA Embedded Image Viewer

Embeds the clicked Image on the Current Site, so you can view it without loading the submission Page


Install this script?
  1. // ==UserScript==
  2. // @name FA Embedded Image Viewer
  3. // @namespace Violentmonkey Scripts
  4. // @match *://*.furaffinity.net/*
  5. // @require https://update.greasyfork.org/scripts/525666/1549449/Furaffinity-Prototype-Extensions.js
  6. // @require https://update.greasyfork.org/scripts/483952/1549453/Furaffinity-Request-Helper.js
  7. // @require https://update.greasyfork.org/scripts/492931/1549454/Furaffinity-Submission-Image-Viewer.js
  8. // @require https://update.greasyfork.org/scripts/485827/1549457/Furaffinity-Match-List.js
  9. // @require https://update.greasyfork.org/scripts/485153/1549461/Furaffinity-Loading-Animations.js
  10. // @require https://update.greasyfork.org/scripts/476762/1549463/Furaffinity-Custom-Pages.js
  11. // @require https://update.greasyfork.org/scripts/475041/1550020/Furaffinity-Custom-Settings.js
  12. // @grant GM_info
  13. // @version 2.4.4
  14. // @author Midori Dragon
  15. // @description Embeds the clicked Image on the Current Site, so you can view it without loading the submission Page
  16. // @icon https://www.furaffinity.net/themes/beta/img/banners/fa_logo.png
  17. // @license MIT
  18. // @homepageURL https://greasyfork.org/scripts/458971-fa-embedded-image-viewer
  19. // @supportURL https://greasyfork.org/scripts/458971-fa-embedded-image-viewer/feedback
  20. // ==/UserScript==
  21. // jshint esversion: 8
  22. (() => {
  23. "use strict";
  24. var __webpack_modules__ = {
  25. 789: (module, __webpack_exports__, __webpack_require__) => {
  26. __webpack_require__.d(__webpack_exports__, {
  27. A: () => __WEBPACK_DEFAULT_EXPORT__
  28. });
  29. var _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(601), _node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0__), _node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(314), ___CSS_LOADER_EXPORT___ = __webpack_require__.n(_node_modules_css_loader_dist_runtime_api_js__WEBPACK_IMPORTED_MODULE_1__)()(_node_modules_css_loader_dist_runtime_noSourceMaps_js__WEBPACK_IMPORTED_MODULE_0___default());
  30. ___CSS_LOADER_EXPORT___.push([ module.id, "#eiv-main {\n position: fixed;\n width: 100vw;\n height: 100vh;\n max-width: 1850px;\n z-index: 999999;\n background: rgba(30, 33, 38, .65);\n}\n\n#eiv-background {\n position: fixed;\n display: flex;\n flex-direction: column;\n left: 50%;\n transform: translate(-50%, 0%);\n margin-top: 20px;\n padding: 20px;\n background: rgba(30, 33, 38, .90);\n border-radius: 10px;\n}\n\n#eiv-submission-container {\n -webkit-user-drag: none;\n}\n\n.eiv-submission-img {\n max-width: inherit;\n max-height: inherit;\n border-radius: 10px;\n user-select: none;\n}\n\n#eiv-button-container {\n position: relative;\n margin-top: 20px;\n margin-bottom: 20px;\n margin-left: 20px;\n}\n\n#eiv-button-wrapper {\n display: flex;\n justify-content: center;\n align-items: center;\n}\n\n#eiv-preview-spinner-container {\n position: absolute;\n top: 50%;\n right: 0;\n transform: translateY(-50%);\n}\n\n.eiv-button {\n margin-left: 4px;\n margin-right: 4px;\n user-select: none;\n}\n", "" ]);
  31. const __WEBPACK_DEFAULT_EXPORT__ = ___CSS_LOADER_EXPORT___;
  32. },
  33. 314: module => {
  34. module.exports = function(cssWithMappingToString) {
  35. var list = [];
  36. list.toString = function toString() {
  37. return this.map((function(item) {
  38. var content = "", needLayer = void 0 !== item[5];
  39. if (item[4]) content += "@supports (".concat(item[4], ") {");
  40. if (item[2]) content += "@media ".concat(item[2], " {");
  41. if (needLayer) content += "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {");
  42. content += cssWithMappingToString(item);
  43. if (needLayer) content += "}";
  44. if (item[2]) content += "}";
  45. if (item[4]) content += "}";
  46. return content;
  47. })).join("");
  48. };
  49. list.i = function i(modules, media, dedupe, supports, layer) {
  50. if ("string" == typeof modules) modules = [ [ null, modules, void 0 ] ];
  51. var alreadyImportedModules = {};
  52. if (dedupe) for (var k = 0; k < this.length; k++) {
  53. var id = this[k][0];
  54. if (null != id) alreadyImportedModules[id] = true;
  55. }
  56. for (var _k = 0; _k < modules.length; _k++) {
  57. var item = [].concat(modules[_k]);
  58. if (!dedupe || !alreadyImportedModules[item[0]]) {
  59. if (void 0 !== layer) if (void 0 === item[5]) item[5] = layer; else {
  60. item[1] = "@layer".concat(item[5].length > 0 ? " ".concat(item[5]) : "", " {").concat(item[1], "}");
  61. item[5] = layer;
  62. }
  63. if (media) if (!item[2]) item[2] = media; else {
  64. item[1] = "@media ".concat(item[2], " {").concat(item[1], "}");
  65. item[2] = media;
  66. }
  67. if (supports) if (!item[4]) item[4] = "".concat(supports); else {
  68. item[1] = "@supports (".concat(item[4], ") {").concat(item[1], "}");
  69. item[4] = supports;
  70. }
  71. list.push(item);
  72. }
  73. }
  74. };
  75. return list;
  76. };
  77. },
  78. 601: module => {
  79. module.exports = function(i) {
  80. return i[1];
  81. };
  82. },
  83. 72: module => {
  84. var stylesInDOM = [];
  85. function getIndexByIdentifier(identifier) {
  86. for (var result = -1, i = 0; i < stylesInDOM.length; i++) if (stylesInDOM[i].identifier === identifier) {
  87. result = i;
  88. break;
  89. }
  90. return result;
  91. }
  92. function modulesToDom(list, options) {
  93. for (var idCountMap = {}, identifiers = [], i = 0; i < list.length; i++) {
  94. var item = list[i], id = options.base ? item[0] + options.base : item[0], count = idCountMap[id] || 0, identifier = "".concat(id, " ").concat(count);
  95. idCountMap[id] = count + 1;
  96. var indexByIdentifier = getIndexByIdentifier(identifier), obj = {
  97. css: item[1],
  98. media: item[2],
  99. sourceMap: item[3],
  100. supports: item[4],
  101. layer: item[5]
  102. };
  103. if (-1 !== indexByIdentifier) {
  104. stylesInDOM[indexByIdentifier].references++;
  105. stylesInDOM[indexByIdentifier].updater(obj);
  106. } else {
  107. var updater = addElementStyle(obj, options);
  108. options.byIndex = i;
  109. stylesInDOM.splice(i, 0, {
  110. identifier,
  111. updater,
  112. references: 1
  113. });
  114. }
  115. identifiers.push(identifier);
  116. }
  117. return identifiers;
  118. }
  119. function addElementStyle(obj, options) {
  120. var api = options.domAPI(options);
  121. api.update(obj);
  122. return function updater(newObj) {
  123. if (newObj) {
  124. if (newObj.css === obj.css && newObj.media === obj.media && newObj.sourceMap === obj.sourceMap && newObj.supports === obj.supports && newObj.layer === obj.layer) return;
  125. api.update(obj = newObj);
  126. } else api.remove();
  127. };
  128. }
  129. module.exports = function(list, options) {
  130. var lastIdentifiers = modulesToDom(list = list || [], options = options || {});
  131. return function update(newList) {
  132. newList = newList || [];
  133. for (var i = 0; i < lastIdentifiers.length; i++) {
  134. var index = getIndexByIdentifier(lastIdentifiers[i]);
  135. stylesInDOM[index].references--;
  136. }
  137. for (var newLastIdentifiers = modulesToDom(newList, options), _i = 0; _i < lastIdentifiers.length; _i++) {
  138. var _index = getIndexByIdentifier(lastIdentifiers[_i]);
  139. if (0 === stylesInDOM[_index].references) {
  140. stylesInDOM[_index].updater();
  141. stylesInDOM.splice(_index, 1);
  142. }
  143. }
  144. lastIdentifiers = newLastIdentifiers;
  145. };
  146. };
  147. },
  148. 659: module => {
  149. var memo = {};
  150. module.exports = function insertBySelector(insert, style) {
  151. var target = function getTarget(target) {
  152. if (void 0 === memo[target]) {
  153. var styleTarget = document.querySelector(target);
  154. if (window.HTMLIFrameElement && styleTarget instanceof window.HTMLIFrameElement) try {
  155. styleTarget = styleTarget.contentDocument.head;
  156. } catch (e) {
  157. styleTarget = null;
  158. }
  159. memo[target] = styleTarget;
  160. }
  161. return memo[target];
  162. }(insert);
  163. if (!target) throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");
  164. target.appendChild(style);
  165. };
  166. },
  167. 540: module => {
  168. module.exports = function insertStyleElement(options) {
  169. var element = document.createElement("style");
  170. options.setAttributes(element, options.attributes);
  171. options.insert(element, options.options);
  172. return element;
  173. };
  174. },
  175. 56: (module, __unused_webpack_exports, __webpack_require__) => {
  176. module.exports = function setAttributesWithoutAttributes(styleElement) {
  177. var nonce = true ? __webpack_require__.nc : 0;
  178. if (nonce) styleElement.setAttribute("nonce", nonce);
  179. };
  180. },
  181. 825: module => {
  182. module.exports = function domAPI(options) {
  183. if ("undefined" == typeof document) return {
  184. update: function update() {},
  185. remove: function remove() {}
  186. };
  187. var styleElement = options.insertStyleElement(options);
  188. return {
  189. update: function update(obj) {
  190. !function apply(styleElement, options, obj) {
  191. var css = "";
  192. if (obj.supports) css += "@supports (".concat(obj.supports, ") {");
  193. if (obj.media) css += "@media ".concat(obj.media, " {");
  194. var needLayer = void 0 !== obj.layer;
  195. if (needLayer) css += "@layer".concat(obj.layer.length > 0 ? " ".concat(obj.layer) : "", " {");
  196. css += obj.css;
  197. if (needLayer) css += "}";
  198. if (obj.media) css += "}";
  199. if (obj.supports) css += "}";
  200. var sourceMap = obj.sourceMap;
  201. if (sourceMap && "undefined" != typeof btoa) css += "\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap)))), " */");
  202. options.styleTagTransform(css, styleElement, options.options);
  203. }(styleElement, options, obj);
  204. },
  205. remove: function remove() {
  206. !function removeStyleElement(styleElement) {
  207. if (null === styleElement.parentNode) return false;
  208. styleElement.parentNode.removeChild(styleElement);
  209. }(styleElement);
  210. }
  211. };
  212. };
  213. },
  214. 113: module => {
  215. module.exports = function styleTagTransform(css, styleElement) {
  216. if (styleElement.styleSheet) styleElement.styleSheet.cssText = css; else {
  217. for (;styleElement.firstChild; ) styleElement.removeChild(styleElement.firstChild);
  218. styleElement.appendChild(document.createTextNode(css));
  219. }
  220. };
  221. }
  222. }, __webpack_module_cache__ = {};
  223. function __webpack_require__(moduleId) {
  224. var cachedModule = __webpack_module_cache__[moduleId];
  225. if (void 0 !== cachedModule) return cachedModule.exports;
  226. var module = __webpack_module_cache__[moduleId] = {
  227. id: moduleId,
  228. exports: {}
  229. };
  230. __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  231. return module.exports;
  232. }
  233. __webpack_require__.n = module => {
  234. var getter = module && module.__esModule ? () => module.default : () => module;
  235. __webpack_require__.d(getter, {
  236. a: getter
  237. });
  238. return getter;
  239. };
  240. __webpack_require__.d = (exports, definition) => {
  241. for (var key in definition) if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
  242. enumerable: true,
  243. get: definition[key]
  244. });
  245. };
  246. __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
  247. __webpack_require__.nc = void 0;
  248. __webpack_require__.d({}, {
  249. yr: () => closeEmbedAfterOpenSetting,
  250. xe: () => loadingSpinSpeedFavSetting,
  251. _d: () => loadingSpinSpeedSetting,
  252. h_: () => openInNewTabSetting,
  253. e2: () => previewQualitySetting,
  254. uL: () => requestHelper
  255. });
  256. class EmbeddedHTML {
  257. static get html() {
  258. return '\n<div id="eiv-background">\n <a id="eiv-submission-container"></a>\n <div id="eiv-button-container">\n <div id="eiv-button-wrapper">\n <a id="eiv-fav-button" type="button" class="eiv-button button standard mobile-fix">⠀⠀</a>\n <a id="eiv-download-button" type="button" class="eiv-button button standard mobile-fix">Download</a>\n <a id="eiv-open-button" type="button" class="eiv-button button standard mobile-fix">Open</a>\n <a id="eiv-open-gallery-button" type="button" class="eiv-button button standard mobile-fix" style="display: none;">Open Gallery</a>\n <a id="eiv-remove-sub-button" type="button" class="eiv-button button standard mobile-fix" style="display: none;">Remove</a>\n <a id="eiv-close-button" type="button" class="eiv-button button standard mobile-fix">Close</a>\n </div>\n <div id="eiv-preview-spinner-container"></div>\n </div>\n</div>';
  259. }
  260. }
  261. var injectStylesIntoStyleTag = __webpack_require__(72), injectStylesIntoStyleTag_default = __webpack_require__.n(injectStylesIntoStyleTag), styleDomAPI = __webpack_require__(825), styleDomAPI_default = __webpack_require__.n(styleDomAPI), insertBySelector = __webpack_require__(659), insertBySelector_default = __webpack_require__.n(insertBySelector), setAttributesWithoutAttributes = __webpack_require__(56), setAttributesWithoutAttributes_default = __webpack_require__.n(setAttributesWithoutAttributes), insertStyleElement = __webpack_require__(540), insertStyleElement_default = __webpack_require__.n(insertStyleElement), styleTagTransform = __webpack_require__(113), styleTagTransform_default = __webpack_require__.n(styleTagTransform), Style = __webpack_require__(789), options = {};
  262. options.styleTagTransform = styleTagTransform_default();
  263. options.setAttributes = setAttributesWithoutAttributes_default();
  264. options.insert = insertBySelector_default().bind(null, "head");
  265. options.domAPI = styleDomAPI_default();
  266. options.insertStyleElement = insertStyleElement_default();
  267. injectStylesIntoStyleTag_default()(Style.A, options);
  268. Style.A && Style.A.locals && Style.A.locals;
  269. const string = class {
  270. static isNullOrWhitespace(str) {
  271. return null == str || "" === str.trim();
  272. }
  273. static isNullOrEmpty(str) {
  274. return null == str || "" === str;
  275. }
  276. };
  277. var LogLevel;
  278. !function(LogLevel) {
  279. LogLevel[LogLevel.Error = 1] = "Error";
  280. LogLevel[LogLevel.Warning = 2] = "Warning";
  281. LogLevel[LogLevel.Info = 3] = "Info";
  282. }(LogLevel || (LogLevel = {}));
  283. class Logger {
  284. static log(logLevel = LogLevel.Warning, ...args) {
  285. if (null == window.__FF_GLOBAL_LOG_LEVEL__) window.__FF_GLOBAL_LOG_LEVEL__ = LogLevel.Error;
  286. if (!(logLevel > window.__FF_GLOBAL_LOG_LEVEL__)) switch (logLevel) {
  287. case LogLevel.Error:
  288. console.error(...args);
  289. break;
  290. case LogLevel.Warning:
  291. console.warn(...args);
  292. break;
  293. case LogLevel.Info:
  294. console.log(...args);
  295. }
  296. }
  297. static setLogLevel(logLevel) {
  298. window.__FF_GLOBAL_LOG_LEVEL__ = logLevel;
  299. }
  300. static logError(...args) {
  301. Logger.log(LogLevel.Error, ...args);
  302. }
  303. static logWarning(...args) {
  304. Logger.log(LogLevel.Warning, ...args);
  305. }
  306. static logInfo(...args) {
  307. Logger.log(LogLevel.Info, ...args);
  308. }
  309. }
  310. var __awaiter = function(thisArg, _arguments, P, generator) {
  311. return new (P || (P = Promise))((function(resolve, reject) {
  312. function fulfilled(value) {
  313. try {
  314. step(generator.next(value));
  315. } catch (e) {
  316. reject(e);
  317. }
  318. }
  319. function rejected(value) {
  320. try {
  321. step(generator.throw(value));
  322. } catch (e) {
  323. reject(e);
  324. }
  325. }
  326. function step(result) {
  327. result.done ? resolve(result.value) : function adopt(value) {
  328. return value instanceof P ? value : new P((function(resolve) {
  329. resolve(value);
  330. }));
  331. }(result.value).then(fulfilled, rejected);
  332. }
  333. step((generator = generator.apply(thisArg, _arguments || [])).next());
  334. }));
  335. };
  336. const embeddedModes = {
  337. watchesFavoriteViewer: "wfv-favorites"
  338. };
  339. class EmbeddedImage extends EventTarget {
  340. constructor(figure) {
  341. super();
  342. this.favRequestRunning = false;
  343. this.downloadRequestRunning = false;
  344. this._imageLoaded = false;
  345. Object.setPrototypeOf(this, EmbeddedImage.prototype);
  346. this.embeddedElem = document.createElement("div");
  347. this.createElements(figure);
  348. const submissionContainer = document.getElementById("eiv-submission-container"), previewLoadingSpinnerContainer = document.getElementById("eiv-preview-spinner-container");
  349. this.loadingSpinner = new window.FALoadingSpinner(submissionContainer);
  350. this.loadingSpinner.delay = loadingSpinSpeedSetting.value;
  351. this.loadingSpinner.spinnerThickness = 6;
  352. this.loadingSpinner.visible = true;
  353. this.previewLoadingSpinner = new window.FALoadingSpinner(previewLoadingSpinnerContainer);
  354. this.previewLoadingSpinner.delay = loadingSpinSpeedSetting.value;
  355. this.previewLoadingSpinner.spinnerThickness = 4;
  356. this.previewLoadingSpinner.size = 40;
  357. document.addEventListener("click", this.onDocumentClick.bind(this));
  358. this.fillSubDocInfos(figure);
  359. }
  360. static get embeddedExists() {
  361. return null != document.getElementById("eiv-main");
  362. }
  363. get onRemove() {
  364. return this._onRemove;
  365. }
  366. set onRemove(handler) {
  367. this._onRemove = handler;
  368. }
  369. onDocumentClick(event) {
  370. if (event.target === document.documentElement) this.remove();
  371. }
  372. onOpenClick() {
  373. if (closeEmbedAfterOpenSetting.value) this.remove();
  374. }
  375. onRemoveSubClick(figure) {
  376. return __awaiter(this, void 0, void 0, (function*() {
  377. const sid = figure.id.trimStart("sid-");
  378. this.remove();
  379. figure.remove();
  380. yield requestHelper.PersonalUserRequests.MessageRequests.NewSubmissions.removeSubmissions([ sid ]);
  381. }));
  382. }
  383. invokeRemove() {
  384. var _a;
  385. null === (_a = this._onRemove) || void 0 === _a || _a.call(this);
  386. this.dispatchEvent(new Event("remove"));
  387. }
  388. remove() {
  389. var _a;
  390. null === (_a = this.embeddedElem.parentNode) || void 0 === _a || _a.removeChild(this.embeddedElem);
  391. document.removeEventListener("click", this.onDocumentClick);
  392. this.invokeRemove();
  393. }
  394. createElements(figure) {
  395. var _a;
  396. this.embeddedElem.id = "eiv-main";
  397. this.embeddedElem.setAttribute("eiv-sid", figure.id.trimStart("sid-"));
  398. this.embeddedElem.innerHTML = EmbeddedHTML.html;
  399. document.getElementById("ddmenu").appendChild(this.embeddedElem);
  400. this.embeddedElem.addEventListener("click", (event => {
  401. if (event.target === this.embeddedElem) this.remove();
  402. }));
  403. const submissionContainer = document.getElementById("eiv-submission-container");
  404. if (openInNewTabSetting.value) submissionContainer.setAttribute("target", "_blank");
  405. submissionContainer.addEventListener("click", this.onOpenClick.bind(this));
  406. const userLink = function getByLinkFromFigcaption(figcaption) {
  407. var _a, _b, _c;
  408. if (null != figcaption) {
  409. const infos = figcaption.querySelectorAll("i");
  410. let userLink = null;
  411. for (const info of Array.from(infos)) if (null !== (_b = null === (_a = info.textContent) || void 0 === _a ? void 0 : _a.toLowerCase().includes("by")) && void 0 !== _b ? _b : false) {
  412. const linkElem = null === (_c = info.parentNode) || void 0 === _c ? void 0 : _c.querySelector("a[href][title]");
  413. if (linkElem) userLink = linkElem.getAttribute("href");
  414. }
  415. return userLink;
  416. }
  417. return null;
  418. }(figure.querySelector("figcaption"));
  419. if (null != userLink) {
  420. const galleryLink = userLink.trimEnd("/").replace("user", "gallery"), scrapsLink = userLink.trimEnd("/").replace("user", "scraps");
  421. if (!window.location.toString().includes(userLink) && !window.location.toString().includes(galleryLink) && !window.location.toString().includes(scrapsLink)) {
  422. const openGalleryButton = document.getElementById("eiv-open-gallery-button");
  423. openGalleryButton.style.display = "block";
  424. openGalleryButton.setAttribute("href", galleryLink);
  425. if (openInNewTabSetting.value) openGalleryButton.setAttribute("target", "_blank");
  426. openGalleryButton.addEventListener("click", this.onOpenClick.bind(this));
  427. }
  428. }
  429. const link = null === (_a = figure.querySelector("a[href]")) || void 0 === _a ? void 0 : _a.getAttribute("href"), openButton = document.getElementById("eiv-open-button");
  430. openButton.setAttribute("href", null != link ? link : "");
  431. if (openInNewTabSetting.value) openButton.setAttribute("target", "_blank");
  432. openButton.addEventListener("click", this.onOpenClick.bind(this));
  433. document.getElementById("eiv-close-button").addEventListener("click", this.remove.bind(this));
  434. const embeddedModesValues = Object.values(embeddedModes);
  435. if (window.location.toString().toLowerCase().includes("msg/submissions") && embeddedModesValues.every((mode => !window.location.toString().toLocaleLowerCase().includes(mode)))) {
  436. const removeSubButton = document.getElementById("eiv-remove-sub-button");
  437. removeSubButton.style.display = "block";
  438. removeSubButton.addEventListener("click", (() => {
  439. this.onRemoveSubClick(figure);
  440. }));
  441. }
  442. document.getElementById("eiv-preview-spinner-container").addEventListener("click", (() => {
  443. this.previewLoadingSpinner.visible = false;
  444. }));
  445. }
  446. fillSubDocInfos(figure) {
  447. return __awaiter(this, void 0, void 0, (function*() {
  448. var _a, _b, _c;
  449. const sid = figure.id.split("-")[1], ddmenu = document.getElementById("ddmenu"), doc = yield requestHelper.SubmissionRequests.getSubmissionPage(sid);
  450. if (null != doc) {
  451. this.submissionImg = doc.getElementById("submissionImg");
  452. const imgSrc = this.submissionImg.src;
  453. let prevSrc = null !== (_a = this.submissionImg.getAttribute("data-preview-src")) && void 0 !== _a ? _a : void 0;
  454. if (!string.isNullOrWhitespace(prevSrc)) {
  455. Logger.logInfo("Preview quality @" + previewQualitySetting.value);
  456. prevSrc = null == prevSrc ? void 0 : prevSrc.replace("@600", "@" + previewQualitySetting.value);
  457. }
  458. const submissionContainer = document.getElementById("eiv-submission-container"), faImageViewer = new window.FAImageViewer(submissionContainer, imgSrc, prevSrc);
  459. faImageViewer.faImage.imgElem.id = "eiv-submission-img";
  460. faImageViewer.faImagePreview.imgElem.id = "eiv-preview-submission-img";
  461. faImageViewer.faImage.imgElem.classList.add("eiv-submission-img");
  462. faImageViewer.faImagePreview.imgElem.classList.add("eiv-submission-img");
  463. faImageViewer.faImage.imgElem.style.maxWidth = faImageViewer.faImagePreview.imgElem.style.maxWidth = window.innerWidth - 40 + "px";
  464. faImageViewer.faImage.imgElem.style.maxHeight = faImageViewer.faImagePreview.imgElem.style.maxHeight = window.innerHeight - ddmenu.clientHeight - 76 - 40 - 100 + "px";
  465. faImageViewer.addEventListener("image-load-start", (() => {
  466. this._imageLoaded = false;
  467. }));
  468. faImageViewer.addEventListener("image-load", (() => {
  469. this._imageLoaded = true;
  470. this.loadingSpinner.visible = false;
  471. this.previewLoadingSpinner.visible = false;
  472. }));
  473. faImageViewer.addEventListener("preview-image-load", (() => {
  474. this.loadingSpinner.visible = false;
  475. if (!this._imageLoaded) this.previewLoadingSpinner.visible = true;
  476. }));
  477. faImageViewer.load();
  478. const url = null === (_b = doc.querySelector('meta[property="og:url"]')) || void 0 === _b ? void 0 : _b.getAttribute("content");
  479. submissionContainer.setAttribute("href", null != url ? url : "");
  480. const result = function getFavKey(doc) {
  481. var _a, _b, _c, _d, _e, _f, _g;
  482. const columnPage = doc.getElementById("columnpage"), navbar = null == columnPage ? void 0 : columnPage.querySelector('div[class*="favorite-nav"]'), buttons = null !== (_a = null == navbar ? void 0 : navbar.querySelectorAll('a[class*="button"][href]')) && void 0 !== _a ? _a : [];
  483. let favButton;
  484. for (const button of Array.from(buttons)) if (null !== (_c = null === (_b = button.textContent) || void 0 === _b ? void 0 : _b.toLowerCase().includes("fav")) && void 0 !== _c ? _c : false) favButton = button;
  485. if (null != favButton) return {
  486. favKey: null !== (_e = null === (_d = favButton.getAttribute("href")) || void 0 === _d ? void 0 : _d.split("?key=")[1]) && void 0 !== _e ? _e : null,
  487. isFav: !(null !== (_g = null === (_f = favButton.getAttribute("href")) || void 0 === _f ? void 0 : _f.toLowerCase().includes("unfav")) && void 0 !== _g ? _g : true)
  488. };
  489. return null;
  490. }(doc), favButton = document.getElementById("eiv-fav-button");
  491. if (null == result) favButton.style.display = "none"; else {
  492. favButton.textContent = result.isFav ? "+Fav" : "-Fav";
  493. favButton.setAttribute("isFav", result.isFav.toString());
  494. favButton.setAttribute("key", null !== (_c = result.favKey) && void 0 !== _c ? _c : "");
  495. favButton.addEventListener("click", (() => {
  496. if (!this.favRequestRunning) this.doFavRequest(sid);
  497. }));
  498. }
  499. const downloadButton = document.getElementById("eiv-download-button");
  500. downloadButton.addEventListener("click", (() => {
  501. if (this.downloadRequestRunning) return;
  502. this.downloadRequestRunning = true;
  503. const loadingTextSpinner = new window.FALoadingTextSpinner(downloadButton);
  504. loadingTextSpinner.delay = loadingSpinSpeedFavSetting.value;
  505. loadingTextSpinner.visible = true;
  506. const iframe = document.createElement("iframe");
  507. iframe.style.display = "none";
  508. iframe.src = this.submissionImg.src + "?eiv-download";
  509. iframe.addEventListener("load", (() => {
  510. this.downloadRequestRunning = false;
  511. loadingTextSpinner.visible = false;
  512. setTimeout((() => {
  513. var _a;
  514. return null === (_a = iframe.parentNode) || void 0 === _a ? void 0 : _a.removeChild(iframe);
  515. }), 100);
  516. }));
  517. document.body.appendChild(iframe);
  518. }));
  519. }
  520. }));
  521. }
  522. doFavRequest(sid) {
  523. return __awaiter(this, void 0, void 0, (function*() {
  524. var _a, _b, _c;
  525. const favButton = document.getElementById("eiv-fav-button");
  526. this.favRequestRunning = true;
  527. const loadingTextSpinner = new window.FALoadingTextSpinner(favButton);
  528. loadingTextSpinner.delay = loadingSpinSpeedFavSetting.value;
  529. loadingTextSpinner.visible = true;
  530. let favKey = null !== (_a = favButton.getAttribute("key")) && void 0 !== _a ? _a : "", isFav = "true" === favButton.getAttribute("isFav");
  531. if (!string.isNullOrWhitespace(favKey)) {
  532. if (isFav) {
  533. favKey = null !== (_b = yield requestHelper.SubmissionRequests.favSubmission(sid, favKey)) && void 0 !== _b ? _b : "";
  534. loadingTextSpinner.visible = false;
  535. if (!string.isNullOrWhitespace(favKey)) {
  536. favButton.setAttribute("key", favKey);
  537. isFav = false;
  538. favButton.setAttribute("isFav", isFav.toString());
  539. favButton.textContent = "-Fav";
  540. } else {
  541. favButton.textContent = "x";
  542. setTimeout((() => favButton.textContent = "+Fav"), 1e3);
  543. }
  544. } else {
  545. favKey = null !== (_c = yield requestHelper.SubmissionRequests.unfavSubmission(sid, favKey)) && void 0 !== _c ? _c : "";
  546. loadingTextSpinner.visible = false;
  547. if (!string.isNullOrWhitespace(favKey)) {
  548. favButton.setAttribute("key", favKey);
  549. isFav = true;
  550. favButton.setAttribute("isFav", isFav.toString());
  551. favButton.textContent = "+Fav";
  552. } else {
  553. favButton.textContent = "x";
  554. setTimeout((() => favButton.textContent = "-Fav"), 1e3);
  555. }
  556. }
  557. this.favRequestRunning = false;
  558. } else favButton.textContent = "x";
  559. }));
  560. }
  561. static addEmbeddedEventForAllFigures() {
  562. return __awaiter(this, void 0, void 0, (function*() {
  563. var _a;
  564. const nonEmbeddedFigures = null !== (_a = document.querySelectorAll("figure:not([embedded])")) && void 0 !== _a ? _a : [];
  565. for (const figure of Array.from(nonEmbeddedFigures)) {
  566. figure.setAttribute("embedded", "true");
  567. figure.addEventListener("click", (event => {
  568. if (event instanceof MouseEvent && event.target instanceof HTMLElement) if (!event.ctrlKey && !event.target.id.includes("favbutton") && "checkbox" !== event.target.getAttribute("type")) {
  569. if (!string.isNullOrWhitespace(event.target.getAttribute("href"))) return;
  570. event.preventDefault();
  571. if (!EmbeddedImage.embeddedExists && figure instanceof HTMLElement) new EmbeddedImage(figure);
  572. }
  573. }));
  574. }
  575. }));
  576. }
  577. }
  578. const customSettings = new window.FACustomSettings("Midori's Script Settings", "FA Embedded Image Viewer Settings"), openInNewTabSetting = customSettings.newSetting(window.FASettingType.Boolean, "Open in new Tab");
  579. openInNewTabSetting.description = "Wether to open links in a new Tab or the current one.";
  580. openInNewTabSetting.defaultValue = true;
  581. const loadingSpinSpeedFavSetting = customSettings.newSetting(window.FASettingType.Number, "Fav Loading Animation");
  582. loadingSpinSpeedFavSetting.description = "The duration that the loading animation, for faving a submission, takes for a full rotation in milliseconds.";
  583. loadingSpinSpeedFavSetting.defaultValue = 600;
  584. const loadingSpinSpeedSetting = customSettings.newSetting(window.FASettingType.Number, "Embedded Loading Animation");
  585. loadingSpinSpeedSetting.description = "The duration that the loading animation of the Embedded element to load takes for a full rotation in milliseconds.";
  586. loadingSpinSpeedSetting.defaultValue = 1e3;
  587. const closeEmbedAfterOpenSetting = customSettings.newSetting(window.FASettingType.Boolean, "Close Embed after open");
  588. closeEmbedAfterOpenSetting.description = "Wether to close the current embedded Submission after it is opened in a new Tab (also for open Gallery).";
  589. closeEmbedAfterOpenSetting.defaultValue = true;
  590. const previewQualitySetting = customSettings.newSetting(window.FASettingType.Option, "Preview Quality");
  591. previewQualitySetting.description = "The quality of the preview image. Value range is 2-6. (Higher values can be slower)";
  592. previewQualitySetting.defaultValue = 400;
  593. previewQualitySetting.options = {
  594. 200: "Very Low",
  595. 300: "Low",
  596. 400: "Medium",
  597. 500: "High",
  598. 600: "Very High"
  599. };
  600. customSettings.loadSettings();
  601. const requestHelper = new window.FARequestHelper(2);
  602. if (customSettings.isFeatureEnabled) {
  603. const matchList = new window.FAMatchList(customSettings);
  604. matchList.matches = [ "net/browse", "net/user", "net/gallery", "net/search", "net/favorites", "net/scraps", "net/controls/favorites", "net/controls/submissions", "net/msg/submissions", "d.furaffinity.net" ];
  605. matchList.runInIFrame = true;
  606. if (matchList.hasMatch) {
  607. const page = new window.FACustomPage("d.furaffinity.net", "eiv-download");
  608. let pageDownload = false;
  609. page.addEventListener("onOpen", (() => {
  610. !function downloadImage() {
  611. let url = window.location.toString();
  612. if (url.includes("?")) {
  613. const parts = url.split("?");
  614. url = parts[0];
  615. }
  616. const download = document.createElement("a");
  617. download.href = url;
  618. download.download = url.substring(url.lastIndexOf("/") + 1);
  619. download.style.display = "none";
  620. document.body.appendChild(download);
  621. download.click();
  622. document.body.removeChild(download);
  623. window.close();
  624. }();
  625. pageDownload = true;
  626. }));
  627. page.checkPageOpened();
  628. if (!pageDownload && !matchList.isWindowIFrame) {
  629. EmbeddedImage.addEmbeddedEventForAllFigures();
  630. window.addEventListener("ei-update-embedded", (() => {
  631. EmbeddedImage.addEmbeddedEventForAllFigures();
  632. }));
  633. }
  634. }
  635. }
  636. })();