ok scnr v2.2 axund runXtimes( t, ms ) w. MSG

ok scnr v2.2 with Message to clibboard btn fxd timeForOneIterationMS runXtimes( tims, intervalinMS )
 avatar
alexunder
javascript
2 years ago
2.9 kB
2
Indexable
Never
// initial conditions 
let runCounter = 0;
let runLimit = 25;
let iterationTimeMS = 500;
let invervalId;
function stop(id) {
  clearInterval(id);
}

/**
* Delay for a number of milliseconds
*/
function sleep(delay) {
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
};

// cpal procedure automator function to be used in interval 
function cpal() {

    var url = document.querySelector("#main_content > div.desktop-dt-wrapper > div > div.desktop-dt-top > div.desktop-dt-top-actionrow > div.card-content-header > a").href;
const splitUrl = url.split('/');
const profileUrl = splitUrl[0] + '//' + splitUrl[2] + '/' + splitUrl[3] + '/' + splitUrl[4];

    var windowObjectReference;
    var windowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";

    function openRequestedPopup(url) {
        windowObjectReference = window.open(url, "tab:" + url, windowFeatures);
    }

    openRequestedPopup(profileUrl);

  
    var likeButton = document.querySelector("#main_content > div.desktop-dt-wrapper > div > div.desktop-dt-top > div.desktop-dt-top-actionrow > div.desktop-dt-top-actionrow-controls > div.desktop-dt-top-actionrow-actions > div > div:nth-child(3) > button");
    
    likeButton.click();
    sleep(iterationTimeMS);
  runCounter++;

  if (runCounter > runLimit ) {
    stop(intervalId);
    console.log("finished running " + runLimit + " times. Interval Removed. Counter has been reset.");
    runCounter = 0;
  }
} // end of cpal procedure automator function for iterator

// prepare message
function fallbackCopyTextToClipboard(text) {
  var textArea = document.createElement("textarea");
  textArea.value = text;
  
  // Avoid scrolling to bottom
  textArea.style.top = "0";
  textArea.style.left = "0";
  textArea.style.position = "fixed";

  document.body.appendChild(textArea);
  textArea.focus();
  textArea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Fallback: Copying text command was ' + msg);
  } catch (err) {
    console.error('Fallback: Oops, unable to copy', err);
  }

  document.body.removeChild(textArea);
}
function copyTextToClipboard(text) {
  if (!navigator.clipboard) {
    fallbackCopyTextToClipboard(text);
    return;
  }
  navigator.clipboard.writeText(text).then(function() {
    console.log('Async: Copying to clipboard was successful!');
  }, function(err) {
    console.error('Async: Could not copy text: ', err);
  });
}

// message content 
var message = "Hey-hey hellö there :) I'm Alex🙂 How is your 🌼🌿summer🍃going so far?🙂"

// write message to clipboard 
copyTextToClipboard(message);

// run procedure  X times  and then stop
function runXTimes(times, timeForOneIterationMS) {
    iterationTimeMS = timeForOneIterationMS;
  runLimit = times;
intervalId = setInterval(cpal, 1100);
}

runXTimes;