Advertisement
Guest User

Untitled

a guest
Mar 17th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 3.83 KB | None | 0 0
  1. //* TITLE Queue Bottom **//
  2. //* VERSION 1.0.0 **//
  3. //* DESCRIPTION **//
  4. //* DEVELOPER Hannah **//
  5. //* FRAME false **//
  6. //* BETA true **//
  7.  
  8. XKit.extensions.queue_bottom = new Object({
  9.  
  10.     running: false,
  11.  
  12.         button_icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QAsACwALDnu/73AAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH4wMRDSUbmU8D/gAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAACFSURBVDjL7dRRDsAQDAbgdtn99Ea4ESfsXjYhitUs2cM8ScSXUn6AxQOvCTNXizFGljYREbbAbXWFP/hBMLU/hGABwE06joh8UaExxk+CCauOPIEWmHiHCrTCmk25gYpYt8sdtIkNn42AdrFh2mSpY8+U8Y/iS/WgEd/5KfsoTLW/bnmFB7VLMHJKhEfZAAAAAElFTkSuQmCC",
  13.         button_ok_icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAABmJLR0QAsACwALDnu/73AAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH4wMRDSUbmU8D/gAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAACFSURBVDjL7dRRDsAQDAbgdtn99Ea4ESfsXjYhitUs2cM8ScSXUn6AxQOvCTNXizFGljYREbbAbXWFP/hBMLU/hGABwE06joh8UaExxk+CCauOPIEWmHiHCrTCmk25gYpYt8sdtIkNn42AdrFh2mSpY8+U8Y/iS/WgEd/5KfsoTLW/bnmFB7VLMHJKhEfZAAAAAElFTkSuQmCC",
  14.  
  15.     run: function() {
  16.         this.running = true;
  17.         if (!XKit.interface.where().queue) {
  18.                         // User is not in a queue, so we're done
  19.             return;
  20.         }
  21.         XKit.tools.init_css("queue_bottom");
  22.  
  23.         XKit.extensions.queue_bottom.init();
  24.  
  25.         XKit.interface.create_control_button("bottom_button", this.button_icon, "Move to bottom", "", this.button_ok_icon);
  26.  
  27.         XKit.post_listener.add("queue_bottom", XKit.extensions.queue_bottom.add_button);
  28.         XKit.extensions.queue_bottom.add_button();
  29.  
  30.     },
  31.  
  32.     init: function() {
  33.         $(document).on("click", ".bottom_button", function(event) {
  34.             // The blue background thing here is just from my debugging
  35.             $(this).css("background","blue");
  36.  
  37.             var m_post = XKit.interface.post($(this));
  38.             var post_id = $(this).attr('data-post-id');
  39.             alert(post_id);
  40.             var m_url = XKit.interface.where().user_url;
  41.             alert(m_url);
  42.             XKit.extensions.queue_bottom.queue_post(post_id, m_url);
  43.         });
  44.     },
  45.  
  46.     add_button: function() {
  47.         $(XKit.interface.get_posts("has-bottom-button")).each(function() {
  48.                 // Add class so we won't hit this post again:
  49.             $(this).addClass("has-bottom-button");
  50.             // Adds the actual button
  51.             XKit.interface.add_control_button(this, "bottom_button", "");
  52.         });
  53.     },
  54.  
  55.     queue_post: function(ID, m_url) {
  56.  
  57.         // This is all a slight edit of submit_shuffle_data() in ShuffleQueue.
  58.         // In submit_shuffle_data(), there's an array of IDs, which are joined together
  59.         // into a string with commas between them. This is just queueing one post
  60.         // so I edited "encodeURIComponent" to just take the single post ID as an
  61.         // argument. I also changed "post_ids=" to "post_id=" in GM_xmlhttpRequest
  62.         // below, just as a guess, but it gives the same 403 error either way.
  63.         // Lastly, "json" is false in the shufflequeue code: the only difference
  64.         // I can tell is that the error code 403 doesn't seem to be specified
  65.         // when json is false.
  66.  
  67.         var form_key = XKit.interface.form_key();
  68.  
  69.         var to_send_single = encodeURIComponent(ID);
  70.  
  71.         GM_xmlhttpRequest({
  72.             method: "POST",
  73.             url: "http://www.tumblr.com/blog/" + m_url + "/order_post_queue/",
  74.             data: "post_ids=" + to_send_single + "&form_key=" + form_key,
  75.             json: false,
  76.             onerror: function(response) {
  77.                 XKit.window.show("Unable to queue post (ONERROR)", "Something went wrong. Sorry", "error", "<div class=\"xkit-button default\" id=\"xkit-close-message\">OK</div>");
  78.                 },
  79.             onload: function(response) {
  80.                 if (response.status !== 200) {
  81.                     XKit.window.show("Unable to queue post", "Something went wrong. Sorry", "error", "<div class=\"xkit-button default\" id=\"xkit-close-message\">OK</div>");
  82.                 }
  83.             }
  84.         });
  85.     },
  86.  
  87.     destroy: function() {
  88.         XKit.post_listener.remove("queue_bottom");
  89.         XKit.tools.remove_css("queue_bottom");
  90.         this.running = false;
  91.     }
  92. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement