instaclear

Lightweight script that monitors your instagram-journey and kills annoying overlays at real-time mode. It let you save photos just using default context-menu.

  1. // ==UserScript==
  2. // @name instaclear
  3. // @namespace sanyabeat.instaclear
  4. // @version 1.14
  5. // @description Lightweight script that monitors your instagram-journey and kills annoying overlays at real-time mode. It let you save photos just using default context-menu.
  6. // @author sanyabeast <a.gvrnsk@gmail.com>
  7. // @match https://www.instagram.com/
  8. // @match https://www.instagram.com/*
  9. // @match https://www.instagram.com/*/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. console.log("%cinstacler works", "color: magenta")
  16.  
  17. const video_dl_btn_style = `
  18. position: absolute;
  19. top: 4px;
  20. right: 4px;
  21. background: transparent;
  22. width: 30px; height: 24px;
  23. text-align: center;
  24. border: none;
  25. cursor: pointer;
  26. `;
  27.  
  28. function trycatch ( cb ) {
  29. try { cb(); } catch ( err ) { console.warn( err ) }
  30. }
  31.  
  32. function enable_hires(){
  33. trycatch ( ()=>{
  34. let processed_count = 0
  35. let image_els = document.querySelectorAll("[srcset]")
  36. for ( let i = 0; i < image_els.length; i++ ) {
  37. let img = image_els[i]
  38. if (!img.ic_processed){
  39. img.sizes = "2000px"
  40. processed_count++
  41. img.ic_processed = true
  42. }
  43. }
  44.  
  45. if (processed_count > 0 ) console.log(`%cjust enabled hi-res for ${processed_count + 1} images`, "color: cyan")
  46. } )
  47.  
  48. return true
  49. }
  50.  
  51. function make_videos () {
  52. let vids = document.querySelectorAll("video")
  53. let processed_count = 0
  54. trycatch( ()=>{
  55. for(let i=0;i<vids.length;i++){
  56. let v = vids[i]
  57. if (v._processed) return
  58. v._processed = true
  59. processed_count++
  60. let p = v.parentNode
  61. if (p && p.parentNode && p.parentNode.parentNode && p.parentNode.parentNode.parentNode ){
  62. p = p.parentNode.parentNode.parentNode
  63. let btn = parse_html(`<a href="${v.src}" target="_blank" style="${video_dl_btn_style}" class="instclr btn">💾</a>`)
  64. p.appendChild(btn)
  65. }
  66. }
  67. } )
  68.  
  69. if (processed_count > 0 ) console.log(`%cjust processed ${processed_count + 1} videos`, "color: #4caf50")
  70. return true
  71. }
  72.  
  73. function parse_html (html){ let d = document.createElement("div"); d.innerHTML = html; let dom = d.children[0]; return dom; }
  74.  
  75. function clear_instagram () {
  76. trycatch ( ()=>{
  77. let cleared_count = 0
  78. let o = document.querySelectorAll("div + div");
  79. for ( let i=0; i<o.length; i++ ){
  80. if (o[i].attributes.length === 1 && o[i].children.length === 0 && o[i].style.zIndex !== "-1") {
  81. cleared_count++
  82. o[i].style.zIndex = "-1"
  83. }
  84. }
  85.  
  86. if (cleared_count > 0 ) console.log(`%cjust cleared ${cleared_count + 1} emptyboxes`, "color: orange")
  87. } )
  88.  
  89. return true
  90. }
  91.  
  92. let observer = new MutationObserver( e => setTimeout( o => enable_hires() && clear_instagram() && make_videos(), 250) );
  93. observer.observe( document.body, { attributes: true, childList: true, subtree: true } );
  94.  
  95. function fire_event (el, etype){
  96. if (!el) return
  97. if (el.fireEvent) {
  98. el.fireEvent('on' + etype);
  99. } else {
  100. var evObj = document.createEvent('Events');
  101. evObj.initEvent(etype, true, false);
  102. el.dispatchEvent(evObj);
  103. }
  104. }
  105.  
  106. document.addEventListener("mousewheel", ( evt )=>{
  107. let view_section_el = document.querySelector("article[role=presentation] > header + div + div")
  108. let next_button_el = document.querySelector(".coreSpriteRightPaginationArrow")
  109. let prev_button_el = document.querySelector(".coreSpriteLeftPaginationArrow")
  110.  
  111. if ( view_section_el ) {
  112. let class_name = view_section_el.className
  113. if ( evt.srcElement.closest(`.${class_name}`) ) {
  114. fire_event( evt.deltaY > 0 ? next_button_el : prev_button_el, "click" )
  115. }
  116.  
  117. }
  118.  
  119. })
  120. })();