Empeopled Minor Enhancements

Provides minor enhancements for Empeopled.com

  1. // ==UserScript==
  2. // @id Emp4
  3. // @name Empeopled Minor Enhancements
  4. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  5. // @grant GM_addStyle
  6. // @version 1.1
  7. // @namespace
  8. // @author TrustyPatches
  9. // @description Provides minor enhancements for Empeopled.com
  10. // @include https://empeopled.com/*
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. GM_addStyle(' \
  15. .OPmain{ \
  16. color: #FFF; \
  17. background-color: #2980B9; \
  18. padding: 2px 0px 4px 3px; \
  19. border-radius: 4px; \
  20. margin-right: 2px; \
  21. } \
  22. .OPmain:hover{ \
  23. color: #2980B9; \
  24. background-color: #BDC3C7; \
  25. } \
  26. .OPmain:focus{ \
  27. background-color: #BDC3C7; \
  28. } \
  29. .OPcom{ \
  30. color: #FFF; \
  31. background-color: #2980B9; \
  32. padding: 8px 0px 11px 4px; \
  33. border-radius: 4px; \
  34. } \
  35. .OPcom:hover{ \
  36. color: #2980B9; \
  37. background-color: #BDC3C7; \
  38. } \
  39. .OPcom:focus{ \
  40. background-color: #BDC3C7;} \
  41. ');
  42.  
  43. var OP = '', loc = '';
  44. var comCount = 0, read_more = 0, x = 0, links_got = 0;
  45. var supported = ['youtube.com', 'youtu.be', 'imgur.com'];
  46. var comSec, links = [];
  47. var q = 50;
  48.  
  49. checkPage();
  50.  
  51. function checkPage() {
  52. //note current page on first run
  53. if (loc.length < 1){
  54. loc = window.location.href;
  55. }
  56. //check if on same page as last check
  57. if (loc == window.location.href){
  58. //check if page is a post
  59. if (loc.indexOf('/p/') > -1 || loc.indexOf('/c/') > -1){
  60. //run getOP if not done already
  61. if (OP.length < 1){
  62. setTimeout(getOP, q);
  63. }
  64. //check comments if getOP already ran
  65. else {
  66. setTimeout(waitForComments, q);
  67. }
  68. }
  69. //if not a post, reinitialize variables and check page again
  70. else {
  71. OP = '';
  72. comCount = 0, read_more = 0, x = 0, links_got = 0;
  73. setTimeout(checkPage, q);
  74. }
  75. }
  76. //note page of current check and check page again
  77. else {
  78. loc = window.location.href;
  79. checkPage();
  80. }
  81. }
  82.  
  83. function getOP() {
  84. //get main post
  85. var post = document.getElementsByClassName('discussion-content');
  86. //make sure main post has loaded
  87. if (post.length > 0){
  88. //find OP's name in post and highlight
  89. OP = post[0].getElementsByClassName('contextualinfo')[0].getElementsByTagName('a')[0];
  90. OP.className = 'OPmain';
  91. OP = OP.href.split('/u/')[1];
  92. }
  93. checkPage();
  94. }
  95.  
  96. function waitForComments() {
  97. //get comments section
  98. comSec = document.getElementsByClassName('discussion-comments');
  99. //if comments section is not loaded, recheck page
  100. if (comSec.length < 1){
  101. checkPage();
  102. }
  103. //if comments section is loaded...
  104. else {
  105. checkComments();
  106. checkPage();
  107. }
  108. }
  109.  
  110. function checkComments() {
  111. //get all comments' context info
  112. var comments = comSec[0].getElementsByClassName('contextualinfo');
  113. var temp = comSec[0].getElementsByTagName('a');
  114. var rm_check = 0;
  115. for (h = 0; temp.length > h; h++){
  116. if (temp[h].innerHTML.indexOf('read more') > -1){
  117. rm_check++;
  118. }
  119. }
  120. //if comments section is not empty and hasn't been checked or number of comments has changed
  121. if (comCount !== comments.length){
  122. getLinks();
  123. comCount = comments.length;
  124. //check for comments by OP and highlight
  125. for (i = 0; comments.length > i; i++){
  126. if (comments[i].getElementsByTagName('a')[0].href.split('/u/')[1] == OP){
  127. comments[i].getElementsByTagName('a')[0].className = 'OPcom';
  128. }
  129. }
  130. }
  131. else if (rm_check !== read_more){
  132. read_more = rm_check;
  133. getLinks();
  134. }
  135. }
  136.  
  137. function getLinks() {
  138. //grab comments
  139. var comments = comSec[0].getElementsByClassName('comment-body');
  140. //run through all comments
  141. for (i = 0; comments.length > i; i++) {
  142. if (comments[i].getElementsByClassName('tog').length < 1){
  143. var comLinks = comments[i].getElementsByTagName('a');
  144. //if the comment has links
  145. if (comLinks.length > 0){
  146. //run through each link
  147. for (j = 0; comLinks.length > j; j++){
  148. if (links_got === 0 && comLinks[j].innerHTML.indexOf('read more') > -1){
  149. read_more++;
  150. }
  151. for (k = 0; supported.length > k; k++){
  152. //if link for supported site
  153. if (comLinks[j].href.indexOf(supported[k]) > -1){
  154. embed(k, comLinks[j]);
  155. x++;
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. links_got = 1;
  163. }
  164.  
  165. function embed(sup, clink) {
  166. var box = document.createElement('span');
  167. var toggle = document.createElement('button');
  168. //if youtube or youtu.be
  169. if (sup === 0 || sup === 1){
  170. //format youtube.com url
  171. if (clink.href.indexOf('youtube') > -1){
  172. links[x] = clink.href.split('v=')[1];
  173. links[x] = 'https://www.youtube.com/embed/' + links[x].split('&')[0];
  174. }
  175. //format youtu.be url
  176. else {
  177. links[x] = 'https://www.youtube.com/embed/' + clink.href.split('be/')[1];
  178. }
  179. toggle.style.cssText = 'margin: 0 3px 8px 5px; padding: 3px 10px; font-size: 0.7em; background-color: #C32023;';
  180. toggle.innerHTML = '&#9658;';
  181. }
  182. //format imgur url
  183. else if (sup === 2){
  184. links[x] = 'http://imgur.com/' + clink.href.split('com/')[1];
  185. toggle.style.cssText = 'margin: 0 3px 8px 5px; padding: 3px 10px; font-size: 0.7em; background-color: #222222; color: #60B101';
  186. toggle.innerHTML = '&#9635;';
  187. }
  188. //create container for embeded content and toggle button
  189. toggle.className = 'btn btn-primary tog lnk' + x;
  190. toggle.setAttribute('id', 'lnk' + x);
  191. clink.parentNode.insertBefore(toggle, clink.nextSibling);
  192. box.style.paddingTop = '10px';
  193. box.className = 'lnk' + x;
  194. box.innerHTML = '';
  195. box.style.display = 'none';
  196. toggle.parentNode.insertBefore(box, toggle.nextSibling);
  197. document.getElementById('lnk' + x).addEventListener('click', open, false);
  198. }
  199.  
  200. //toggle for embed container
  201. function open() {
  202. var max_width = $(window).width() * 0.75;
  203. var box = document.getElementsByClassName(this.id)[1];
  204. var link = links[this.id.split('lnk')[1]];
  205. //toggle open/closed
  206. if (box.innerHTML.length < 1){
  207. box.style.display = 'block';
  208. if (link.indexOf('youtube') > -1){
  209. box.innerHTML = '<iframe width="600" height="450" src="' + link + '" frameborder="0" allowfullscreen></iframe>'
  210. }
  211. else if (link.indexOf('imgur') > -1){
  212. box.innerHTML = '<img src="' + link + '">';
  213. setTimeout(function(){
  214. if ($(box.firstChild).width() > max_width){
  215. var ratio = $(box.firstChild).width() / $(box.firstChild).height();
  216. box.firstChild.width = max_width;
  217. box.firstChild.height = max_width / ratio;
  218. }
  219. }, 500);
  220. }
  221. }
  222. else {
  223. box.style.display = 'none';
  224. box.innerHTML = '';
  225. }
  226. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址