Guest User

Untitled

a guest
Oct 28th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.54 KB | None | 0 0
  1. if (!window.VkStorySaverLib) {
  2. window.VkStorySaverLib = {
  3. forMutation: function(mutation) {
  4. var a, diva, key, prevLink;
  5. var story = document.body.getElementsByClassName("story_view_row_active")[0];
  6. if (!story) {
  7. window.observer.disconnect();
  8. } else {
  9. if (story.getElementsByClassName("vk story saver").length) {
  10. diva = story.getElementsByClassName("vk story saver")[0];
  11. if (diva.getElementsByTagName("a").length) {
  12. a = diva.getElementsByTagName("a")[0];
  13. prevLink = a.href;
  14. } else {
  15. a = document.createElement("a");
  16. a.innerText = "Сохранить";
  17. }
  18. key = false;
  19. } else {
  20. diva = document.createElement("div");
  21. diva.className = "vk story saver";
  22. diva.style.marginLeft = "6px";
  23. a = document.createElement("a");
  24. a.innerText = "Сохранить";
  25. story.getElementsByClassName("story_view_info")[0].appendChild(diva);
  26. key = true;
  27. }
  28. if (document.body.getElementsByClassName("story_view_video").length) {
  29. if (document.body.getElementsByClassName("story_view_video")[0].currentSrc.indexOf(".mp4") != -1) {
  30. a.href = document.body.getElementsByClassName("story_view_video")[0].currentSrc;
  31. if (a.href.indexOf("?") > -1) {
  32. a.href = a.href.substring(0, a.href.indexOf("?"));}
  33. a.download = ".mp4";
  34. }
  35. } else {
  36. if (document.body.getElementsByClassName("story_view_photo started").length) {
  37. if (document.body.getElementsByClassName("story_view_photo started")[0].currentSrc.indexOf(".jpg") != -1) {
  38. a.href = document.body.getElementsByClassName("story_view_photo started")[0].currentSrc;
  39. if (a.href.indexOf("?") > -1) {
  40. a.href = a.href.substring(0, a.href.indexOf("?"));}
  41. a.download = ".jpg";
  42. }
  43. } else {
  44. if (document.body.getElementsByClassName("story_view_photo").length) {
  45. if (document.body.getElementsByClassName("story_view_photo")[0].currentSrc.indexOf(".jpg") != -1) {
  46. a.href = document.body.getElementsByClassName("story_view_photo")[0].currentSrc;
  47. if (a.href.indexOf("?") > -1) {
  48. a.href = a.href.substring(0, a.href.indexOf("?"));}
  49. a.download = ".jpg";
  50. }
  51. }
  52. }
  53. }
  54. if (a.href && (a.href != prevLink)) {
  55. diva.appendChild(a);
  56. }
  57. }
  58. }
  59. }
  60. }
  61.  
  62. if (document.body.getElementsByClassName("story_view_row_active").length) {
  63. if (!document.body.getElementsByClassName("story_view_row_active")[0].getElementsByClassName("vk story saver").length) {
  64. var diva1 = document.createElement("div");
  65. diva1.className = "vk story saver";
  66. diva1.style.marginLeft = "6px";
  67. document.body.getElementsByClassName("story_view_row_active")[0].getElementsByClassName("story_view_info")[0].appendChild(diva1);
  68. var target = document.getElementsByClassName("story_view_row_active")[0];
  69. window.observer = new MutationObserver(function(mutations) {
  70. mutations.forEach(function(mutation) {
  71. VkStorySaverLib.forMutation(mutation);
  72. })
  73. });
  74. var config = {
  75. childList: true,
  76. characterData: true,
  77. subtree: true
  78. };
  79. observer.observe(target, config);
  80. }
  81. var checkFlag = true,
  82. check = document.body.getElementsByClassName("story_view_row_active")[0];
  83. if (check) {
  84. check = check.getElementsByClassName("vk story saver")[0];
  85. if (check) {
  86. check = check.getElementsByTagName("a")[0];
  87. if (check) {
  88. check = check.href;
  89. if (check) {
  90. checkFlag = false;
  91. }
  92. }
  93. }
  94. }
  95. if (checkFlag) {
  96. VkStorySaverLib.forMutation(null);
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment