ImgurComment500Limit

Brings the 500 character limit comments to non "beta" imgur users

  1. // ==UserScript==
  2. // @name ImgurComment500Limit
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description Brings the 500 character limit comments to non "beta" imgur users
  6. // @author SleepProgger
  7. // @match https://imgur.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function _injectME(){
  16. function _func(){
  17. Imgur.Caption.Reply.defaultProps.maxLength = 500;
  18. var __hook_ajax = $.ajax; $.ajax = function(x){
  19. // The only way i found to circumvent the character limit is to use the "new" API.
  20. // There probably is some nicer way, but meh this works
  21. if(!x.url || ! x.url.startsWith("/gallery/action/caption/")){
  22. return __hook_ajax(x);
  23. }
  24. // Rewrite request to the "new" API format
  25. var nData = {};
  26. var s = x.url.split("/"); // JS Are you kidding me ? WHY NO RSPLIT ?
  27. nData.post_id = s[s.length - 1];
  28. nData.comment = x.data.caption;
  29. nData.platform = "api";
  30. nData.parent_id = x.data.parent_id;
  31. nData.has_admin_badge = false;
  32. x.data = JSON.stringify(nData);
  33. x.url = "https://api.imgur.com/comment/v1/comments?client_id=" + imgur._.apiClientId;
  34. x.xhrFields = { withCredentials:true };
  35. x.headers = {'Content-Type': 'application/vnd.imgur.v1+json'};
  36. // We also have to rewrite the response now which sucks
  37. x.dataFilter = function (r, type) {
  38. r = JSON.parse(r);
  39. var ret = {
  40. success: true,
  41. data: {
  42. caption: {
  43. id: r.id,
  44. hash: r.post.id,
  45. caption: r.comment,
  46. author: r.account.username,
  47. author_id: r.account_id,
  48. ups: r.upvote_count,
  49. downs: r.downvote_count,
  50. best_score: 0.2, // No clue where to get this, so lets just fake it
  51. points: r.point_count,
  52. datetime: r.created_at.replace("T", " ").replace("Z", ""), // Do i suck at JS; or does JS suck ?
  53. parent_id: r.parent_id,
  54. deleted: r.deleted_at != null,
  55. on_album: r.post.is_album,
  56. album_cover: r.post.cover_id, // Not sure this is correct
  57. title: "", // No clue. Post title this reply is on ?
  58. platform: "yoMomma",
  59. has_admin_badge: false, // Naw, don't have that
  60. }
  61. }
  62. };
  63. return JSON.stringify(ret);
  64. }
  65. return __hook_ajax(x);
  66. };
  67. };
  68. function _waitForImgur(){
  69. if(window.Imgur && Imgur.Caption){
  70. console.log("Imgur is ready");
  71. _func();
  72. return;
  73. }
  74. console.log("Waiting for imgur");
  75. setTimeout(_waitForImgur, 250); // This is pretty ugly, should use some observer instead, but i am lazy.
  76. }
  77. _waitForImgur();
  78. }
  79. var s = document.createElement('script');
  80. s.textContent = '(' + _injectME + ')()';
  81. console.log("Inject into", document.location, ":", s.textContent);
  82. document.head.appendChild(s);
  83.  
  84. })();