Advertisement
Guest User

Untitled

a guest
Feb 4th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Display views & uploader
  3. // @author nonamethanks
  4. // @namespace display-views-uploader
  5. // @description Display views and original uploader in the post page
  6. // @version 1.0
  7. // @include *://*.donmai.us/posts/*
  8. // ==/UserScript==
  9.  
  10.  
  11. function starter(element, method) {
  12. if (typeof window[method] === "undefined") {
  13. window[method] = setInterval(function() {
  14. if ($(element).length) {
  15. method();
  16. clearInterval(window[method])
  17. }
  18. }, 100);
  19. }
  20. }
  21.  
  22. function postViews() {
  23. async function _postViews() {
  24. const post_id = $("meta[name='post-id']").attr("content")
  25. $.get(
  26. `https://isshiki.donmai.us/post_views/${post_id}`,
  27. function(data) {
  28. $(`<li>Views: ${data}</li>`).insertAfter("#post-information > ul > li:nth-child(6)");
  29. }
  30. );
  31. }
  32.  
  33. starter("#post-information", _postViews);
  34. }
  35.  
  36. function displayUploader() {
  37. async function _displayUploader() {
  38. let uploader_id = $("#image-container").attr("data-uploader-id");
  39. let uploader_href = "/users/" + uploader_id;
  40. $.getJSON(
  41. "https://danbooru.donmai.us" + uploader_href + ".json",
  42. function (data) {
  43. let uploader = data["name"];
  44. let uploader_level = data["level_string"].toLowerCase();
  45. let li_element = $("<li>Uploader: </li>");
  46. let a_element = $(`<a class="user-post-uploader with-style">${uploader}</a>`);
  47. li_element.append(a_element);
  48. a_element.attr("href", uploader_href);
  49. a_element.addClass("user-" + uploader_level);
  50. li_element.insertAfter("#post-information > ul > li:nth-child(2)");
  51. }
  52. );
  53.  
  54. }
  55.  
  56. starter("#post-information", _displayUploader);
  57. }
  58.  
  59. postViews();
  60. displayUploader();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement