Greasy Fork is available in English.

jcNextPic

Arrangement Pictures and Click a button to view Next Pic. 排列圖片(由左而右、由上而下),按一個按鈕便可依序往下的瀏覽圖片.

  1. // ==UserScript==
  2. // @name jcNextPic
  3. // @namespace http://localhost/jc/
  4. // @require https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.1.min.js
  5. // @include http://*/discuz/thread*
  6. // @include http://*/viewthread*
  7. // @include http://*/thread-*
  8. // @include http://blog.xuite.net/*
  9. // @include http://*/viewtopic.php*
  10. // @include http://www.cecet.cn/*
  11. // @include http://*.77tuba.com/*
  12. // @include http://77tuba.com/*
  13. // @include http://*.blogspot.com/*
  14. // @include http://www.mobile01.com/*
  15. // @include http://*/forum.php*viewthread*tid*
  16. // @include http://*.pixnet.net/*
  17. // @include http://*.mop.com/*
  18. // @include http://*.sina.com.cn/*
  19. // @include http://*/*/archives/*
  20. // @include http://*.stockstar.com/*html
  21. // @include http://*.soso.com/*
  22. // @include http://*.pixnet.net/blog/post/*
  23. // @include http://bbs.taobao.com/catalog/thread/*
  24. // @include http://mm.taobao.com/*
  25. // @include http://www.dong.tw/*
  26. // @include http://www.dongtw.com/*
  27. // @include http://*dong.tw/*
  28. // @.downloadURL https://userscripts.org/scripts/source/82324.user.js
  29. // @.updateURL https://userscripts.org/scripts/source/82324.meta.js
  30. // @copyright 2013+, JC
  31. // @description Arrangement Pictures and Click a button to view Next Pic. 排列圖片(由左而右、由上而下),按一個按鈕便可依序往下的瀏覽圖片.
  32. // @grant GM_log
  33. // @grant GM_addStyle
  34. // @version 2014.09.10.22h.00m
  35. // ==/UserScript==
  36.  
  37.  
  38.  
  39. (function($) {
  40.  
  41.  
  42.  
  43. GM_addStyle("div#jcNextPic { position:fixed; cursor:pointer; top:10px; right:10px; border:1px solid #66CCFF; background-color:yellow; padding:2px; font-size:11px; z-index:100; }");
  44. GM_addStyle("span.jcButton { cursor:pointer; border:1px solid #66CCFF; background-color:yellow; padding:2px; font-size:11px; z-index:10000; }");
  45.  
  46. var jc_nextpic_mark = 'NP';
  47. var jc_click_last_time = 0;
  48. var jc_support_link = true; // 支援 facebook , weibo 等連結
  49. var created_array = false;
  50. var array_imgs = [];
  51. var imgs_count = 0;
  52. var img_min_w = 150;
  53.  
  54. letsJQuery();
  55.  
  56.  
  57. // All your GM code must be inside this function
  58. function letsJQuery() {
  59. //alert($); // check if the dollar (jquery) function works
  60. //alert($().jquery); // check jQuery version
  61. if ( ($(document).width() >= 500) && ($(document).height() >= 300) && ($(window).width() >= 500) ) {
  62. window.setTimeout(function() {
  63. doJCNextPic();
  64. } , 100);
  65. }
  66. }
  67.  
  68.  
  69. function create_img_array() {
  70. // create img array
  71. //$(document).scrollTop(0);
  72. if (!created_array) {
  73. $('img').each(function() {
  74. if ( ($(this).width() > 200) && ($(this).height() > 200) ) {
  75. array_imgs.push(this);
  76. imgs_count++;
  77. }
  78. });
  79. var includeSites = ["facebook.com", "weibo.com", "twitter.com", "instagram.com"]; // 需要的 KEY WORD
  80. var excludeSites = ["share", "ck101"]; // 不需要的 KEY WORD
  81. var ahref;
  82. var aSite = '';
  83. var aExcludeStr = '';
  84. var hasExcludeStr = false;
  85. $('a').each(function() {
  86. if ($(this).attr('href')) {
  87. ahref = $(this).attr('href');
  88. for (idx in includeSites) {
  89. aSite = includeSites[idx];
  90. if (-1!=ahref.indexOf(aSite)) { // 網址含有 includeSites 其中之一
  91. hasExcludeStr = false;
  92. for (idx2 in excludeSites) {
  93. aExcludeStr = excludeSites[idx2];
  94. hasExcludeStr = (-1!=ahref.indexOf(aExcludeStr));
  95. if (hasExcludeStr) { break; }
  96. } // for
  97. if (!hasExcludeStr) { // 未含不需要的字串
  98. array_imgs.push(this);
  99. imgs_count++;
  100. }
  101. }
  102. } // for
  103. }
  104. });
  105. /*
  106. try {
  107. $('iframe').each(function() {
  108. var iframe_imgs = this.contentWindow.document.images;
  109. for (i = 0; i < iframe_imgs.length; i++) {
  110. if ( (iframe_imgs[i].width > 200) && (iframe_imgs[i].height > 200) ) {
  111. array_imgs.push(iframe_imgs[i]);
  112. imgs_count++;
  113. }
  114. }
  115. });
  116. } catch (e) {
  117. }
  118. */
  119. created_array = true;
  120. }
  121. }
  122.  
  123. // All your GM code must be inside this function
  124. function doJCNextPic() {
  125. var html = '';
  126. var link_id = 10000;
  127. var goto_top = false;
  128.  
  129. // View Next Pic
  130. //next_pic_html = '<span id="jcNextPic" style="position:fixed; cursor:pointer; top:10px; right:10px; border:1px solid #66CCFF; background-color:yellow; padding:2px; font-size:11px; z-index:10;">Next Pic</span>';
  131. next_pic_html = '<div id="jcNextPic" class="jcArea">' +
  132. '<input type="button" id="jcNextPicBtn" value="Next Pic" />' +
  133. '<input type="button" id="jcNextPicHideBtn" value="-" title="Hide" /><br />' +
  134. '<span id="jcAutoWidthBtn" class="jcButton">auto</span>' +
  135. '<span id="jc100WidthBtn" class="jcButton">100%</span>' +
  136. '<span id="jcCrossImagesBtn" class="jcButton">排</span>' +
  137. '<span id="jcEasyViewBtn" class="jcButton">易讀</span>' +
  138. '</div>';
  139. $('body').prepend( next_pic_html );
  140. //$(document).scroll(function() { $('#jcNextPic').text( $(document).scrollTop() ); });
  141. $('#jcNextPicHideBtn').click(function() {
  142. // Hide All jc area
  143. //$('#jcNextPic').hide();
  144. $('.jcArea').hide();
  145. });
  146. $('#jcNextPicBtn').click(function() {
  147. var t = new Date;
  148. var click_time = t.getTime();
  149. if ((click_time - jc_click_last_time) < 200) { return; }
  150. jc_click_last_time = click_time;
  151. create_img_array();
  152. if (goto_top) {
  153. $(document).scrollTop(0);
  154. //$('#jcNextPic').text('Next Pic');
  155. $('#jcNextPicBtn').val('Next Pic');
  156. goto_top = false;
  157. }
  158. var doc_top = $(document).scrollTop();
  159. var oked = false;
  160. var jump_nexted = true;
  161. $.map(array_imgs , function(elm , idx) {
  162. //$('body').append( idx + ': ' + $(document).scrollTop() + ' ;;; ' + doc_top + '<br />' );
  163. if (!oked) {
  164. elm.scrollIntoView();
  165. if ($(document).scrollTop() >= (doc_top+1)) {
  166. oked = true;
  167. if ('a' == elm.tagName.toLowerCase()) {
  168. $(elm).css('border', '5px solid blue');
  169. setTimeout(function() {
  170. $(elm).css('border', '0px solid blue');
  171. }, 2000);
  172. }
  173. }
  174. }
  175. });
  176. if (doc_top == $(document).scrollTop()) {
  177. jump_nexted = false;
  178. }
  179. if (!jump_nexted) {
  180. //$('#jcNextPic').text('Goto First');
  181. $('#jcNextPicBtn').val('Goto First');
  182. goto_top = true;
  183. }
  184. });
  185. $('#jcAutoWidthBtn').click(function() {
  186. $('img').filter(function() {
  187. return (parseInt($(this).height()) >= img_min_w);
  188. }).each(function() {
  189. jcSetImageAutoWH($(this));
  190. });
  191. });
  192. $('#jc100WidthBtn').click(function() {
  193. $('img').filter(function() {
  194. return (parseInt($(this).height()) >= img_min_w);
  195. }).each(function() {
  196. $(this).css('width' , '100%')
  197. .css('height' , '100%');
  198. });
  199. });
  200. $('#jcCrossImagesBtn').on('click' , function() {
  201. $('#jcAutoWidthBtn').trigger('click');
  202. doJcNextPicCrossImages();
  203. });
  204. $('#jcEasyViewBtn').click(function() {
  205. doJcEasyView();
  206. });
  207.  
  208. // 將 Lazy Image 顯示出來
  209. window.setTimeout(function() {
  210. doLoadLazyImgs();
  211. } , 3000);
  212. }
  213.  
  214.  
  215. function doJcNextPicCrossImages() {
  216. // 排列圖片
  217. var container = $('body:eq(0)'),
  218. cw = container.width(),
  219. container2 = $('<div></div>'),
  220. wh = $(window).height(),
  221. ih = 0,
  222. iw = 0;
  223. container.prepend(container2);
  224. $('body').find('img').each(function() {
  225. if ( ($(this).width() > 200) && ($(this).height() > 200) ) {
  226. ih = $(this).height();
  227. iw = $(this).width();
  228. if (ih > wh) {
  229. // 縮小圖片高度
  230. $(this).height(wh)
  231. .width(iw*(wh/ih))
  232. .css('border-right' , '1px solid yellow');
  233. }
  234. container2.append($(this));
  235. $(this).css('vertical-align' , 'top');
  236. }
  237. });
  238. // 點擊圖檔->原始大小
  239. $('img').on('click', function() {
  240. jcSetImageAutoWH($(this), true);
  241. });
  242. }
  243.  
  244. function jcSetImageAutoWH(Qobj , showBorder = false) {
  245. // 設置圖檔寬高為 auto
  246. Qobj.css('width', 'auto')
  247. .css('height', 'auto')
  248. .removeAttr('height')
  249. .removeAttr('width');
  250. if (showBorder) {
  251. Qobj.css('border', '1px solid blue');
  252. }
  253. }
  254.  
  255. function doJcEasyView() {
  256. // 易讀性
  257. (function(){
  258. var newSS, styles='* {background:white !important; color:black !important; line-height: 180% !important; font-size: 0.85cm !important; width:auto !important; margin: 0 0 0 0 !important; position:static !important;} :link, :link * { color: #0000EE !important;} :visited, :visited * { color: #551A8B !important;}';
  259. if(document.createStyleSheet) {
  260. document.createStyleSheet("javascript:'"+styles+"'");
  261. } else {
  262. newSS=document.createElement('link');
  263. newSS.rel='stylesheet';
  264. newSS.href='data:text/css,'+escape(styles);
  265. document.getElementsByTagName("head")[0].appendChild(newSS);
  266. }})();
  267. }
  268.  
  269. function doLoadLazyImgs() {
  270. // 將 Lazy Image 顯示出來
  271. var flags = '';
  272. var regex = new RegExp('http(s|)://((.*?)(([^.]*?)\.([^.]*?)))/' , flags);
  273. var matches = regex.exec(location.href);
  274. globalHost = matches[2]; // ex: www.wretch.cc
  275. globalDomain = matches[4]; // ex: wretch.cc
  276. var arr1 = [ ['taobao.com' , 'data-ks-lazyload'] ,
  277. ['mop.com' , 'data-original'] ,
  278. ['dongtw.com' , 'data-original']
  279. ];
  280. for (var i = 0; i < arr1.length; i++) {
  281. var a = arr1[i][0];
  282. var b = arr1[i][1];
  283. if (a == globalDomain) {
  284. $('img').each(function() {
  285. if ($(this).attr(b)) {
  286. var imgsrc = $(this).attr(b);
  287. var src_def = '';
  288. if ($(this).attr('src')) {
  289. src_def = $(this).attr('src');
  290. }
  291. if (src_def != imgsrc) {
  292. $(this).attr('src' , imgsrc)
  293. .removeAttr(b);
  294. }
  295. }
  296. });
  297. }
  298. } // for i
  299. /*
  300. if ('taobao.com' == globalDomain) {
  301. $('img').each(function() {
  302. if ($(this).attr('data-ks-lazyload')) {
  303. var imgsrc = $(this).attr('data-ks-lazyload');
  304. $(this).attr('src' , imgsrc)
  305. .removeAttr('data-ks-lazyload');
  306. }
  307. });
  308. }
  309. */
  310. }
  311.  
  312.  
  313. })(jQuery);
  314.