Greasy Fork is available in English.

Cuddlypuss

Displays both sides of a cover on Cuddlyoctopus.com, and shows the sfw/nsfw version on mouseover(depends on which version of the site you are viewing).

  1. // ==UserScript==
  2. // @name Cuddlypuss
  3. // @version 0.1.1
  4. // @description Displays both sides of a cover on Cuddlyoctopus.com, and shows the sfw/nsfw version on mouseover(depends on which version of the site you are viewing).
  5. // @author Kayla355
  6. // @match https://cuddlyoctopus.com/shop/*
  7. // @run-at document-start
  8. // @grant none
  9. // @namespace https://greasyfork.org/users/12437
  10. // @change 0.1.1 - Fixed an issue with multiple new page loads being triggered.
  11. // ==/UserScript==
  12. var sfw;
  13. var style = document.createElement('style');
  14. style.type = "text/css";
  15. style.innerHTML = `.container { width: 80%; }
  16. #hoverimg img {transition: opacity .3s ease-in-out !important;}
  17. #hoverimg:hover img:nth-of-type(3), #hoverimg:hover img:nth-of-type(4) { opacity: 0; }
  18. #hoverimg img.dttop:hover { opacity: 0; }
  19. .dakithumb { transition: none !important; height: 100% !important; width: 49.8% !important; }
  20. .dakithumb:nth-of-type(2), .dakithumb:nth-of-type(4) { left: 50% !important; right: 0; }`;
  21. document.querySelector('head').appendChild(style);
  22.  
  23. var state = {
  24. xhr: false,
  25. loading: function() {
  26. if(!this.xhr && !document.querySelector('.lmp_products_loading')) {
  27. return false;
  28. }
  29. return true;
  30. },
  31. appendable: false,
  32. observer: null,
  33. append: function() {
  34. var _this = this;
  35. // Mutations observer
  36. _this.observer = new MutationObserver(function(mutations) {
  37. for(var i=0; i < mutations.length; i++) {
  38. let mutation = mutations[i];
  39. for(var j=0; j < mutation.removedNodes.length; j++) {
  40. if(mutation.removedNodes[j].className == "lmp_products_loading") {
  41. _this.appendable = true;
  42. _this.observer.disconnect();
  43. }
  44. }
  45. }
  46. });
  47. _this.observer.observe(document.querySelector('.products'), {childList: true});
  48. }
  49. };
  50.  
  51. window.addEventListener('DOMContentLoaded', function() {
  52. sfw = !!+window.location.search.replace(/.*sfw\=([0-9]).*/i, '$1') || !!+document.cookie.replace(/.*sfw_version\=([0-9]).*/i, '$1');
  53. load_next_images(true);
  54.  
  55. // Pagination observer
  56. var observer = new MutationObserver(function(mutations) {
  57. for(var i=0; i < mutations.length; i++) {
  58. let mutation = mutations[i];
  59. for(var j=0; j < mutation.addedNodes.length; j++) {
  60. if(mutation.addedNodes[j].className == "lmp_products_loading") {
  61. load_next_images();
  62. }
  63. }
  64. }
  65. });
  66.  
  67. observer.observe(document.querySelector('.products'), {childList: true});
  68. });
  69.  
  70.  
  71. function load_next_images(firstLoad) {
  72. state.xhr = true;
  73. state.append();
  74. var url = (firstLoad) ? window.location.href : document.querySelector('.pagination-item-next-link').href;
  75. url = (!window.location.search) ? url+'?sfw='+((sfw) ? 0:1):url.replace(/(&|\?)sfw=[0-9]|$/, '$1sfw='+((sfw) ? 0:1));
  76. var xhr = new XMLHttpRequest();
  77. xhr.open('GET', url);
  78. xhr.onload = function() {
  79. var container = document.implementation.createHTMLDocument().documentElement;
  80. container.innerHTML = xhr.responseText;
  81.  
  82. appendImages(container, firstLoad);
  83. state.xhr = false;
  84. };
  85. xhr.send();
  86. }
  87.  
  88. function appendImages(container, firstLoad) {
  89. // Mutations observer
  90. var observer = new MutationObserver(function(mutations) {
  91. for(var i=0; i < mutations.length; i++) {
  92. let mutation = mutations[i];
  93. for(var j=0; j < mutation.removedNodes.length; j++) {
  94. if(mutation.removedNodes[j].className == "lmp_products_loading") {
  95. attacher();
  96. }
  97. }
  98. }
  99. });
  100.  
  101. var append = function(imageContainer) {
  102. var parent = imageContainer.parentNode;
  103. while(parent && parent.tagName !== "A") {
  104. parent = parent.parentNode;
  105. }
  106. var target = document.querySelector('a[href="'+ parent.href +'"]' + ' #hoverimg');
  107. if(target) {
  108. target.insertBefore(imageContainer, target.querySelector('img:first-of-type'));
  109. } else {
  110. // Failsafe when the target doesn't exist yet for whatever reason.
  111. setTimeout(append.bind(null, imageContainer), 1000);
  112. }
  113. };
  114.  
  115. var attacher = function() {
  116. var imageContainers = container.querySelectorAll('.dakithumb');
  117. for(var i=imageContainers.length-1; i >= 0; i--) {
  118. append(imageContainers[i]);
  119. }
  120. observer.disconnect();
  121. state.observer.disconnect();
  122. };
  123.  
  124. observer.observe(document.querySelector('.products'), {childList: true});
  125. if(firstLoad || state.appendable) attacher();
  126. }