Image BG Toggle

Toggles the background colour for images in the browser

当前为 2016-09-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Image BG Toggle
  3. // @namespace PXgamer
  4. // @version 1.2
  5. // @description Toggles the background colour for images in the browser
  6. // @author PXgamer
  7. // @include /.*\.(JPG|PNG|GIF|JPEG).*/
  8. // @require https://code.jquery.com/jquery-3.1.0.min.js
  9. // @grant none
  10. // ==/UserScript==
  11. /*jshint multistr: true */
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function changeImageBG() {
  17. if (col == 'black') {
  18. $('body').css('background-color', col);
  19. if (allowGrey) { col = 'grey'; }
  20. else { col = 'white'; }
  21. }
  22. else if (col == 'grey') {
  23. $('body').css('background-color', col);
  24. col = 'white';
  25. }
  26. else if (col == 'white') {
  27. $('body').css('background-color', col);
  28. col = 'black';
  29. }
  30. else {
  31. $('body').css('background-color', 'white');
  32. col = 'black';
  33. }
  34. }
  35.  
  36. var allowGrey = false;
  37. var col = 'black';
  38. if (document.contentType.indexOf('image') > -1) {
  39. console.info('IBGT: IS IMAGE');
  40. $('body').append('<span id="bgToggle" style="right: 5px; cursor: pointer; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; z-index: 999999; position: fixed; float: right; background-color: white; border: 1px solid grey; border-radius: 2px; margin: 5px; padding: 2px; font-family: fantasy;">TOGGLE BG</span>');
  41.  
  42. $('#bgToggle').on('click', function() {changeImageBG(); });
  43. var keys = {
  44. ctrl: false,
  45. b: false
  46. };
  47. $(document.body).on('keydown', function (e) {
  48. if (event.keyCode == 17) {
  49. keys.ctrl = true;
  50. } else if (event.keyCode == 66) {
  51. keys.b = true;
  52. }
  53. if (keys.ctrl && keys.b) {
  54. changeImageBG();
  55. }
  56. });
  57. $(document.body).keyup(function(e) {
  58. if (event.keyCode == 17) {
  59. keys.ctrl = false;
  60. } else if (event.keyCode == 66) {
  61. keys.b = false;
  62. }
  63. });
  64. }
  65. })();