Posted on

Browser Extensions And User Snippets

Chrome Extensions And User Snippets

Most Open Source Intelligence collection techniques rely on your web browser for accessing and acquiring data. Chrome Extensions play a major role in helping extract and archive data from web pages. Extensions provide you with the “easy” button, when it comes collecting the data. User Snippets are multiline Javascript functions that you can run directly against web pages that you are trying to extract data from. 

Chrome Extensions: Are pre-made software programs that run within your browser. Extensions can be installed through the chrome store or loaded directly from your file system. Extension allow you to customize the look, feel, interactivity and functionality during your web browsing session. The Chrome store has over 180K extensions available for download. If you can think it, there is a chrome extension for it. 

User Snippets: User snippets in Chrome are a feature of the Chrome Developer Tools (DevTools) that allow developers to run Javascript programs on demand.  User Snippets can function like a recipe book for accessing and acquiring data from a variety of web sites. They can easily be reused across different websites, that use the same underlying technology. The best part about User Snippets is they can readily be modified and updated at anytime.

OSINT LIAR is a highly adaptive next generation collection tool. Get your free trial today at https://osintliar.com

User Snippet: Expand YouTube Comments And Save Using OSINT LIAR

				
					/**
* OSINT LIAR: Snippet for collecting comments from a YouTube video and save the page and the comments into OSINT LIAR.
* Buy or get a Trial license for OSINT LIAR from https://osintliar.com 
* DO NOT REPRODUCE OR COPY WITH PERMISSION
*/

(function expandAllComments() {
    let lastScrollHeight = -1;
    let saved = false;
    let lastNodeCount = 0;
    let tries = 0;
    const EXTENSION_ID = 'mgmandbcdaecndcllojppohiekdbhcie';
    const distance = 150; // How many pixels to scroll on each step
    let scrolled = 0;
    let flag = false;
    const MAX_TRIES = 40; // Set higher if you have a high latency internet connection or saving is happening too early.
    let intervalId = setInterval(() => {
        // Find all "Show more" and reply buttons buttons for comments and replies
        const buttons = document.querySelectorAll(
            '.ytd-item-section-renderer, .ytd-continuation-item-renderer, .ytd-replies-alt, .more-button'
        );
              
        // Click each "Show more" button if it's not already clicked
        buttons.forEach(button => {
            if (isButtonVisible(button) && !button.getAttribute('clicked')) {
                button.click();
                button.setAttribute('clicked', true);
            }
        });

        let exit = false;
        if(exit){
            flag = true;
            console.log('exiting')
        }

        // Scroll down to load more comments
        window.scrollBy(0, distance);
        scrolled += distance;
      
        // Check if the scroll position is at the bottom and no more comments to load
        if (flag) {
            clearInterval(intervalId);
            console.log('All comments expanded. Scrolling to the top...');
            window.scrollTo(0, 0); // Scroll back to the top of the page
            if(!saved){
              saved = true;
              delay(2000)
              // Save the page into OSINT LIAR              
              chrome.runtime.sendMessage(EXTENSION_ID, {captureTab: true},
                function(response) {
                  console.log(response)
                }
              );                    
            }              
        } 
        else {
            previousHeight = lastScrollHeight;
            lastScrollHeight = document.documentElement.scrollHeight;
            const element = document.getElementById('sections');
            let height = element.clientHeight;                              
            flag = (lastScrollHeight > height + 5000 && tries > MAX_TRIES)
            if(flag){
                console.log("scroll height flag")
            }

            if(lastNodeCount === element.children.length){
              tries++;
            }
            if(!flag && tries > MAX_TRIES && previousHeight === lastScrollHeight){  
              flag = true;
              console.log("Max tries exceeded.")  
            }
            else if(lastNodeCount !== element.children.length || previousHeight !== lastScrollHeight)
            {
              lastNodeCount = element.children.length
              tries = 0;
            }
                    
        }
                }, 750); // Adjust time interval as needed, depends on your latency
            })();


function delay(milliseconds){
    return new Promise(resolve => {
        setTimeout(resolve, milliseconds);
    });
}

function isButtonVisible(button) {

    if (!button) {
        console.log('Button not found');
        return false;
    }

    const style = window.getComputedStyle(button);

    // Check for display property
    if (style.display === 'none') return false;

    // Check for visibility property
    if (style.visibility === 'hidden') return false;

    // Check for opacity
    if (style.opacity === '0') return false;

    // Check if the button has dimensions
    if (button.offsetWidth === 0 && button.offsetHeight === 0) return false;

    // Check if the button is in the viewport
    const rect = button.getBoundingClientRect();
    const inViewport = rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);

    return inViewport;
}

				
			

Need Help Getting It Working? Let Us Know.