jc_FitImg

將圖放大. 保護眼睛.

  1. // ==UserScript==
  2. // @name jc_FitImg
  3. // @namespace http://localhost/jc/
  4. // @.require http://192.168.10.15/files/jquery-1.7.2.min.js
  5. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  6. // @include http://tieba.baidu.com/f?kz=*
  7. // @include http://*/article/reader.php*
  8. // @include http://blog.*
  9. // @include http://*/html/*/*.html
  10. // @include http://*/html/book/*.shtml
  11. // @include http://*/*/*.html
  12. // @include http://*/viewthread*
  13. // @include http://*/discuz/thread*
  14. // @include http://*/thread-*
  15. // @include http://*/viewtopic.php*
  16. // @include http://www.cecet.cn/*
  17. // @include http://*.blogspot.com/*
  18. // @exclude http://tt.mop.com/*
  19. // @exclude http://www.piring.com/bbs/*
  20. // @exclude http://ck101.com/*
  21. // @exclude http://imagetwist.com/*/*.jpg.html
  22. // @exclude http://www.dlsite.com/*
  23. // @description 將圖放大. 保護眼睛.
  24. // @version 2014.09.22.23h
  25. // @grant GM_addStyle
  26. // @grant GM_log
  27. // ==/UserScript==
  28.  
  29.  
  30.  
  31. (function($) {
  32.  
  33. GM_addStyle("span#jcNextPic { position:fixed; cursor:pointer; top:10px; right:10px; border:1px solid #66CCFF; background-color:yellow; padding:2px; font-size:11px; z-index:100; }");
  34. GM_addStyle("span.jcButton { cursor:pointer; border:1px solid #66CCFF; background-color:yellow; color:black; padding:2px; font-size:11px; z-index:100; }");
  35.  
  36. /*
  37. // Add jQuery
  38. function loadjQuery() {
  39. if('undefined' == typeof unsafeWindow.jQuery) {
  40. if (!GM_JQ) {
  41. //alert('1apple:1');
  42. var GM_JQ = document.createElement('script');
  43. //GM_JQ.src = 'http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js';
  44. //GM_JQ.src = 'http://jqueryjs.googlecode.com/files/jquery-1.3.min.js';
  45. //GM_JQ.src = 'http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js';
  46. //GM_JQ.src = 'http://127.0.0.1:100/jquery-1.3.2.min.js';
  47. //GM_JQ.src = 'http://192.168.10.15/files/jquery-1.4.2.min.js';
  48. //GM_JQ.src = 'http://192.168.10.15/files/jquery-1.4.4.min.js';
  49. GM_JQ.src = 'http://192.168.10.15/files/jquery-1.7.2.min.js';
  50. //GM_JQ.src = 'http://code.jquery.com/jquery-1.4.4.min.js';
  51. //GM_JQ.src = 'http://192.168.10.15/files/jquery-1.6.4.min.js';
  52. //GM_JQ.src = 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4.min.js';
  53. GM_JQ.type = 'text/javascript';
  54. document.getElementsByTagName('head')[0].appendChild(GM_JQ);
  55. //alert('1apple:2');
  56. }
  57. }
  58. }
  59.  
  60. if ( ( 'undefined' == typeof unsafeWindow.jQuery ) || ( 'undefined' == typeof unsafeWindow.jQuery.noConflict ) ) {
  61. loadjQuery();
  62. }
  63. */
  64.  
  65. // Check if jQuery's loaded
  66. /*
  67. function GM_wait() {
  68. if('undefined' == typeof unsafeWindow.jQuery) {
  69. window.setTimeout(GM_wait,100);
  70. } else {
  71. $ = unsafeWindow.jQuery;
  72. //var $ = unsafeWindow.jQuery.noConflict(true);
  73. letsJQuery();
  74. }
  75. }
  76.  
  77. GM_wait();
  78.  
  79. */
  80.  
  81. letsJQuery();
  82.  
  83. var created_array = false;
  84. var array_imgs = [];
  85. var imgs_count = 0;
  86.  
  87. function create_img_array() {
  88. // create img array
  89. //$(document).scrollTop(0);
  90. if (!created_array) {
  91. var imgs = document.images.length;
  92. for(i = 0; i< imgs; i++) {
  93. objImg = $(document.images[i]);
  94. if ( (objImg.width() > 200) && (objImg.height() > 200) ) {
  95. array_imgs.push(this);
  96. imgs_count++;
  97. }
  98. } // for
  99. try {
  100. $('iframe').each(function() {
  101. var iframe_imgs = this.contentWindow.document.images;
  102. for (i = 0; i < iframe_imgs.length; i++) {
  103. if ( (iframe_imgs[i].width > 200) && (iframe_imgs[i].height > 200) ) {
  104. array_imgs.push(iframe_imgs[i]);
  105. imgs_count++;
  106. }
  107. }
  108. });
  109. } catch (e) {
  110. }
  111. created_array = true;
  112. }
  113. }
  114.  
  115. // All your GM code must be inside this function
  116. function dojcResizeImage() {
  117. var html = '';
  118. var link_id = 10000;
  119. var goto_top = false;
  120.  
  121. // View Next Pic
  122. //var 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>';
  123. var next_pic_html = '<span id="jcNextPic"><input type="button" id="jcNextPicBtn" value="Next Pic" /><input type="button" id="jcNextPicHideBtn" value="-" title="Hide" /><br />' +
  124. '<span id="jcAutoWidthBtn" class="jcButton">auto</span>' +
  125. '<span id="jc100WidthBtn" class="jcButton">100%</span>' +
  126. '<span id="jcCrossImagesBtn" class="jcButton">排</span>' +
  127. '</span>';
  128. $('body').prepend( next_pic_html );
  129. //$(document).scroll(function() { $('#jcNextPic').text( $(document).scrollTop() ); });
  130. var imgCollection = $('img').filter(function(index) {
  131. return (($(this).width() > 100) && ($(this).height() > 100));
  132. });
  133. if (0 == imgCollection.length) {
  134. $('#jcNextPic').hide();
  135. } else {
  136. $('#jcNextPic').show();
  137. }
  138. $('#jcNextPicHideBtn').click(function() {
  139. $('#jcNextPic').hide();
  140. });
  141. $('#jcNextPicBtn').click(function() {
  142. create_img_array();
  143. if (goto_top) {
  144. $(document).scrollTop(0);
  145. //$('#jcNextPic').text('Next Pic');
  146. $('#jcNextPicBtn').val('Next Pic');
  147. goto_top = false;
  148. }
  149. var doc_top = $(document).scrollTop();
  150. var oked = false;
  151. var jump_nexted = true;
  152. $.map(array_imgs , function(elm , idx) {
  153. //$('body').append( idx + ': ' + $(document).scrollTop() + ' ;;; ' + doc_top + '<br />' );
  154. if (!oked) {
  155. elm.scrollIntoView();
  156. if ($(document).scrollTop() >= (doc_top+1)) {
  157. oked = true;
  158. }
  159. }
  160. });
  161. if (doc_top == $(document).scrollTop()) {
  162. jump_nexted = false;
  163. }
  164. if (!jump_nexted) {
  165. //$('#jcNextPic').text('Goto First');
  166. $('#jcNextPicBtn').val('Goto First');
  167. goto_top = true;
  168. }
  169. });
  170. $('#jcAutoWidthBtn').click(function() {
  171. var imgs = document.images.length;
  172. for(i = 0; i< imgs; i++) {
  173. objImg = $(document.images[i]);
  174. objImg.css('width' , 'auto')
  175. .css('height' , 'auto');
  176. } // for
  177. });
  178. $('#jc100WidthBtn').click(function() {
  179. var imgs = document.images.length;
  180. for(i = 0; i< imgs; i++) {
  181. objImg = $(document.images[i]);
  182. if (objImg.width() > 300) {
  183. objImg.css('width' , '100%')
  184. .css('height' , '100%');
  185. }
  186. } // for
  187. });
  188. // 排列圖片
  189. $('#jcCrossImagesBtn').click(function() {
  190. doJcCrossImages();
  191. });
  192. }
  193.  
  194.  
  195.  
  196.  
  197. //if (!$) { GM_wait(); }
  198.  
  199. // All your GM code must be inside this function
  200. function restoreSourceImage() {
  201.  
  202. doJcMainWork();
  203. }
  204.  
  205.  
  206. function doJcMainWork() {
  207. var doCount = 0;
  208.  
  209. //GM_log('jc_fitimg START doJcMainWork().');
  210. //GM_log('jc_fitimg IMG count = ' + $('img').length);
  211. var imgs = document.images.length;
  212. for(i = 0; i< imgs; i++) {
  213. try {
  214. objImg = $(document.images[i]);
  215. var ImgWidth = objImg.width();
  216. var ImgHeight = objImg.height();
  217. if ( (ImgWidth > 250) && (ImgHeight > 500) && ("undefined" == typeof objImg.attr('jcFitImg')) ) {
  218. var InnerWidth = window.innerWidth;
  219. var InnerHeight = window.innerHeight;
  220. //if (InnerWidth > 1200) { InnerWidth = 1200; }
  221. if (true) {
  222. // 取得 Image 的 Left
  223. var elem = document.images[i];
  224. var xPos = elem.offsetLeft;
  225. var tempEl = elem.offsetParent;
  226. while (tempEl != null) {
  227. xPos += tempEl.offsetLeft;
  228. tempEl = tempEl.offsetParent;
  229. }
  230. var ImgLeft = xPos;
  231. // ...
  232. //var ratio = (InnerWidth - Math.min(ImgLeft,32)) / ImgWidth;
  233. var ratio = (InnerWidth - ImgLeft) / ImgWidth;
  234. var ImgNewWidth = ImgWidth * ratio - 52;
  235. var ImgNewHeight = ImgHeight * ratio - 32;
  236. var LimitWidth = 1200;
  237. if (ImgNewWidth > LimitWidth) {
  238. ImgNewHeight = ImgNewHeight * (LimitWidth/ImgNewWidth);
  239. ImgNewWidth = LimitWidth;
  240. } else {
  241. ImgNewWidth = LimitWidth;
  242. ImgNewHeight = ImgHeight * (ImgNewWidth/ImgWidth);
  243. }
  244. //GM_log('jc_fitimg IMG src = ' + $(this).attr('src') );
  245. //GM_log('jc_fitimg IMG ' + doCount + ' -> Old WH=' + ImgWidth + 'x' + ImgHeight );
  246. //GM_log('jc_fitimg IMG ' + doCount + ' -> New WH = ' + ImgNewWidth + 'x' + ImgNewHeight);
  247. doCount++;
  248. objImg.width(ImgNewWidth)
  249. .height(ImgNewHeight)
  250. .css('border' , '1px groove red')
  251. .css('z-index' , '10')
  252. .attr('jcFitImg' , true);
  253. //.attr('title' , 'Left = ' + ImgLeft + ' :: Old = ' + ImgWidth + 'x' + ImgHeight + ' :: New = ' + ImgNewWidth + 'x' + ImgNewHeight);
  254. }
  255. }
  256. } catch(e) {
  257. GM_log('jc_fitimg EXCEPT in 255 line.');
  258. }
  259. }; // for
  260. if (doCount > 0) {
  261. //alert('jc Fit Images count = ' + doCount);
  262. }
  263.  
  264. /*
  265. window.setTimeout( function() {
  266. doJcMainWork();
  267. } , 5000 );
  268. */
  269. }
  270.  
  271. function letsJQuery() {
  272.  
  273. var url_self = window.location.href;
  274. try {
  275. var url_parent = window.parent.location.href;
  276. } catch(e) {
  277. var url_parent = '';
  278. }
  279. if ( url_self == url_parent ) {
  280.  
  281. window.setTimeout(function() {
  282. if ( (typeof jc_nextpic_mark == 'undefined') || ('NP' != jc_nextpic_mark) ) {
  283. //alert($);
  284. window.setTimeout(function() {
  285. restoreSourceImage();
  286. } , 100);
  287. window.setInterval(function() {
  288. restoreSourceImage();
  289. } , 5000);
  290. window.setTimeout(dojcResizeImage , 100);
  291. }
  292. } , 3000);
  293. window.setTimeout(function() {
  294. /*
  295. var imgs = document.images.length;
  296. for(i = 0; i< imgs; i++) {
  297. $(document.images[i]).css('width', '1800px');
  298. }
  299. */
  300. }, 1000);
  301. }
  302. }
  303.  
  304.  
  305. function doJcCrossImages() {
  306. // 排列圖片
  307. console.log("exec doJcCrossImages()");
  308. var container = $('body');
  309. var cw = container.width();
  310. var container2 = $('<div id="divJcCrossImagesArea"></div>');
  311. container.prepend(container2);
  312. container.find('img').each(function() {
  313. if ( ($(this).width() > 200) && ($(this).height() > 200) ) {
  314. if ($(this).parent()[0].tagName == 'A') {
  315. container2.append('<span style="width:30px; height:30px;"><a href="' + $(this).parent().attr('href') + '" target="_blank">LINK</a></span>');
  316. }
  317. container2.append($(this));
  318. $(this).css('vertical-align' , 'top');
  319. }
  320. });
  321. }
  322.  
  323.  
  324.  
  325. //GM_log('GM_run_jc_piring_add_url' + document.documentElement.innerHTML.match(re));
  326.  
  327. })(jQuery);
  328.  

QingJ © 2025

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