F95 Latest Update Saver

Save your current Latest Update Page configurations & load it when you need it!

  1. // ==UserScript==
  2. // @name F95 Latest Update Saver
  3. // @namespace 1330126-edexal
  4. // @match *://f95zone.to/sam/latest_alpha/*
  5. // @grant GM.setValue
  6. // @grant GM.getValue
  7. // @icon https://external-content.duckduckgo.com/ip3/f95zone.to.ico
  8. // @license Unlicense
  9. // @version 1.1
  10. // @author Edexal
  11. // @description Save your current Latest Update Page configurations & load it when you need it!
  12. // ==/UserScript==
  13. (async function () {
  14. //Apply custom styles in a style tag
  15. function applyCSS(css) {
  16. let styleEl = document.querySelector("style");
  17. if (styleEl === null) {
  18. styleEl = document.createElement('style');
  19. }
  20. styleEl.appendChild(document.createTextNode(css));
  21. document.head.appendChild(styleEl);
  22. }
  23. function getStyles(){
  24. return `
  25. @keyframes notice {
  26. 0% {opacity:0;}
  27. 30% {opacity:1;}
  28. 60% {opacity:1;}
  29. 100% {opacity:0;};
  30. }
  31. #save-notice {
  32. position: fixed;
  33. z-index: 8;
  34. top: 33%;
  35. left: 40vw;
  36. background-color:#2d2d2d;
  37. color: yellow;
  38. border-radius: 10px;
  39. border: 2pt outset #6ce65b;
  40. box-shadow: -1px 0px 5px #cece92;
  41. width: 120px;
  42. padding-top:15px;
  43. padding-bottom:15px;
  44. font-size: 18px;
  45. font-weight:bold;
  46. text-align:center;
  47. opacity: 0;
  48. }
  49. .save-anim {
  50. animation: 3s notice ease-in-out;
  51. }
  52. .save-bg {
  53. opacity: 0.6;
  54. }
  55.  
  56. a.fa-hdd::before, a.fa-save::before {
  57. color: #f0c315 !important;
  58. }
  59. div#filter-block_settings h4 {
  60. color: #fc9b46 !important;
  61. }
  62.  
  63. `;
  64. }
  65. function addSaveNotice(){
  66. let notice = document.createElement('div');
  67. notice.id = 'save-notice';
  68. let txtNode = document.createTextNode('Saved!');
  69. notice.append(txtNode);
  70. document.body.append(notice);
  71.  
  72. applyCSS(getStyles());
  73. }
  74. function createSection(){
  75. let section = document.createElement('div');
  76. section.id = 'filter-block_settings';
  77. section.classList.add('filter-block');
  78. return section;
  79. }
  80. function createHeader(){
  81. let h = document.createElement('h4');
  82. h.classList.add('filter-block_title');
  83. let txtNode = document.createTextNode('Settings');
  84. h.append(txtNode);
  85. return h;
  86. }
  87. function createSectWrap(){
  88. let outerContainer = document.createElement('div');
  89. outerContainer.classList.add('filter-block_content', 'filter-block_h');
  90. return outerContainer;
  91. }
  92.  
  93. //Utility function for creating buttons
  94. function createBtn(name,classNames,eventFunc){
  95. let innerContainer = document.createElement('div');
  96. innerContainer.id = `btn-settings_${name}`;
  97. innerContainer.classList.add('filter-block_button-wrap');
  98.  
  99. let a = document.createElement('a');
  100. a.href = "#";
  101. a.setAttribute('data-settings',name);
  102. a.classList.add('filter-block_button', ...classNames);
  103. a.addEventListener('click',eventFunc);
  104.  
  105. let label = document.createElement('div');
  106. label.classList.add('filter-block_button-label');
  107. let labelTxtNode = document.createTextNode(`${name[0].toUpperCase()}${name.substring(1)}`);
  108. label.append(labelTxtNode);
  109.  
  110.  
  111. innerContainer.append(a,label);
  112. return innerContainer;
  113. }
  114.  
  115. function saveEvent(e){
  116. e.preventDefault();
  117. GM.setValue('url',location.href);
  118. let saveNotice = document.querySelector('#save-notice');
  119. let saveNoticeBG = document.querySelector('#top');
  120. if (!!!saveNotice.classList.contains('save-anim')){
  121. saveNotice.classList.add('save-anim');
  122. saveNoticeBG.classList.add('save-bg');
  123. setTimeout(()=>{
  124. saveNotice.classList.remove('save-anim');
  125. saveNoticeBG.classList.remove('save-bg');
  126. },3000)
  127. }
  128. }
  129.  
  130. async function loadAsyncEvent(e){
  131. e.preventDefault();
  132. try {
  133. let url = await GM.getValue('url');
  134. location.href = url;
  135. }catch(err){
  136. console.error(err);
  137. }
  138. }
  139. function createSaveBtn(){
  140. return createBtn('save', ['fas','fa-save'], saveEvent);
  141. }
  142. function createLoadBtn(){
  143. return createBtn('load',['fas', 'fa-hdd'], loadAsyncEvent);
  144. }
  145.  
  146. function getSettingsSect(){
  147. let settingsSect = createSection();
  148. let header = createHeader();
  149. let contentWrap = createSectWrap();
  150. let saveBtn = createSaveBtn();
  151. let loadBtn = createLoadBtn();
  152. contentWrap.append(loadBtn,saveBtn);
  153. settingsSect.append(header,contentWrap);
  154.  
  155. return settingsSect;
  156. }
  157.  
  158. function addSettingsSect(){
  159. let drawerEl = document.querySelector('.content-block_filter');
  160. let titleEl = document.querySelector('.content-block_filter-title');
  161. titleEl.after(getSettingsSect());
  162.  
  163. addSaveNotice();
  164. }
  165.  
  166. addSettingsSect();
  167.  
  168. })().catch(err => console.error(err));