Auto Like & Follow Instagram Feed + UI + Persist

Automatically like and follow posts on Instagram feed with toggle UI and persistent settings.

  1. // ==UserScript==
  2. // @name Auto Like & Follow Instagram Feed + UI + Persist
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description Automatically like and follow posts on Instagram feed with toggle UI and persistent settings.
  6. // @match https://www.instagram.com/
  7. // @author Teja Sukmana
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=instagram.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. let countL = 0;
  16. let countF = 0;
  17. const maxLikesPerSession = 500;
  18. const maxFollowsPerSession = 500;
  19. const sessionBreakTime = 15 * 60 * 1000;
  20.  
  21. // Load from localStorage or set default
  22. let enableLiking = localStorage.getItem('enableLiking') !== 'false';
  23. let enableFollowing = localStorage.getItem('enableFollowing') !== 'false';
  24.  
  25. function createToggleUI() {
  26. const container = document.createElement('div');
  27. container.style.position = 'fixed';
  28. container.style.top = '6%';
  29. container.style.right = '10px';
  30. container.style.zIndex = '9999';
  31. container.style.background = 'rgba(0,0,0,.6)';
  32. container.style.border = '1px solid #ccc';
  33. container.style.borderRadius = '8px';
  34. container.style.padding = '10px';
  35. container.style.boxShadow = '0 0 10px rgba(0,0,0,0.2)';
  36. container.style.fontFamily = 'Arial, sans-serif';
  37.  
  38. container.innerHTML = `
  39. <label><input type="checkbox" id="likeToggle"> Enable Like</label><br>
  40. <label><input type="checkbox" id="followToggle"> Enable Follow</label><br>
  41. <a href="https://instagram.com/kohardsi">More Tools</a>
  42. `;
  43.  
  44. document.body.appendChild(container);
  45.  
  46. const likeCheckbox = document.getElementById('likeToggle');
  47. const followCheckbox = document.getElementById('followToggle');
  48.  
  49. likeCheckbox.checked = enableLiking;
  50. followCheckbox.checked = enableFollowing;
  51.  
  52. likeCheckbox.addEventListener('change', function () {
  53. enableLiking = this.checked;
  54. localStorage.setItem('enableLiking', enableLiking);
  55. console.log("Liking: " + (enableLiking ? "Enabled" : "Disabled"));
  56. });
  57.  
  58. followCheckbox.addEventListener('change', function () {
  59. enableFollowing = this.checked;
  60. localStorage.setItem('enableFollowing', enableFollowing);
  61. console.log("Following: " + (enableFollowing ? "Enabled" : "Disabled"));
  62. });
  63. }
  64.  
  65. function getRandomTime(min, max) {
  66. return Math.floor(Math.random() * (max - min + 1) + min) * 1000;
  67. }
  68.  
  69. function isFollowButton(button) {
  70. return button.querySelector('div[dir="auto"]')?.innerText === 'Ikuti';
  71. }
  72.  
  73. function likeAndFollowFeedPosts() {
  74. if ((countL >= maxLikesPerSession && enableLiking) || (countF >= maxFollowsPerSession && enableFollowing)) {
  75. console.log("Reached max likes or follows for this session. Taking a break.");
  76. setTimeout(() => {
  77. countL = 0;
  78. countF = 0;
  79. likeAndFollowFeedPosts();
  80. }, sessionBreakTime);
  81. return;
  82. }
  83.  
  84. if (enableLiking) {
  85. let likeButtons = document.querySelectorAll('svg[aria-label="Suka"]');
  86. likeButtons.forEach((likeButton) => {
  87. if (countL < maxLikesPerSession) {
  88. let button = likeButton.closest('div[role="button"]');
  89. if (button) {
  90. button.click();
  91. countL++;
  92. }
  93. }
  94. });
  95. }
  96.  
  97. if (enableFollowing) {
  98. let followButtons = document.querySelectorAll('button');
  99. followButtons.forEach((followButton) => {
  100. if (countF < maxFollowsPerSession && isFollowButton(followButton)) {
  101. followButton.click();
  102. countF++;
  103. }
  104. });
  105. }
  106.  
  107. console.log("Total Likes: " + countL + " | Total Follows: " + countF);
  108.  
  109. window.scrollBy(0, 550);
  110.  
  111. setTimeout(likeAndFollowFeedPosts, getRandomTime(5, 15));
  112. }
  113.  
  114. function likeAndFollowIndividualPosts() {
  115. if ((countL >= maxLikesPerSession && enableLiking) || (countF >= maxFollowsPerSession && enableFollowing)) {
  116. console.log("Reached max likes or follows for this session. Taking a break.");
  117. setTimeout(() => {
  118. countL = 0;
  119. countF = 0;
  120. likeAndFollowIndividualPosts();
  121. }, sessionBreakTime);
  122. return;
  123. }
  124.  
  125. if (enableLiking) {
  126. let likeButton = document.querySelector('svg[aria-label="Suka"]');
  127. if (likeButton && countL < maxLikesPerSession) {
  128. let button = likeButton.closest('div[role="button"]');
  129. if (button) {
  130. button.click();
  131. countL++;
  132. }
  133. }
  134. }
  135.  
  136. if (enableFollowing) {
  137. let followButton = document.querySelector('button');
  138. if (followButton && countF < maxFollowsPerSession && isFollowButton(followButton)) {
  139. followButton.click();
  140. countF++;
  141. }
  142. }
  143.  
  144. console.log("Total Likes: " + countL + " | Total Follows: " + countF);
  145.  
  146. let nextButton = document.querySelector('._aaqg button');
  147. if (nextButton) {
  148. nextButton.click();
  149. }
  150.  
  151. setTimeout(likeAndFollowIndividualPosts, getRandomTime(10, 30));
  152. }
  153.  
  154. createToggleUI();
  155.  
  156. if (location.href === 'https://www.instagram.com/') {
  157. likeAndFollowFeedPosts();
  158. } else {
  159. likeAndFollowIndividualPosts();
  160. }
  161. })();