/**
 * Konichiwa~
 *
 * This is a content script that runs directly on the page.
 * It contains the global functions/methods that can be used
 * throughout the 9anime website.
 */ import { Intent , IRuntimeMessage , IRuntimeResponse } from "../lib/common" ; import * as enhancements from "../lib/enhancements" ; import { loadSettings } from "../lib/utils" ; console . info ( "9anime Companion 1.0.0 (Global Script)" ) ; toastr . options . timeOut = 10000 ; toastr . options . closeButton = true ; console . info ( "%c[✔] Attaching enhancements" , "color: lightgreen;" ) ; enhancements . globalShortcuts ( ) ; enhancements . enhancedSearch ( ) ; enhancements . scrollToTop ( ) ; loadSettings ( [ "remAds" , "remSocialShare" , ] ) . then ( settings => { if ( settings . remAds ) { console . info ( "%c[✔] Removing global ad placeholders" , "color: lightgreen;" ) ; let adsSelectors = [ ".myass" , ] ; for ( let i of adsSelectors ) { $ ( i ) . remove ( ) ; } console . info ( "%c[✔] Removing iframes" , "color: lightgreen;" ) ; $ ( "iframe" ) . each ( ( _ , el ) => { if ( ! /disqus/ . test ( el . src ) ) { $ ( el ) . remove ( ) ; } } ) ; } if ( settings . remSocialShare ) { console . info ( "%c[✔] Removing social share box" , "color: lightgreen;" ) ; let socialSelectors = [ ".addthis_native_toolbox" , ".home-socials" , ] ; for ( let i of socialSelectors ) { document . querySelectorAll ( i ) . forEach ( el => { el . remove ( ) ; } ) ; } } } ) ; let changelogToast = ( versionName ) => { toastr . info ( `Updated to ${ versionName }.<br>` + "<button class='nac__toast-btn' id='nac__toast__open-changelog'>View changes</button>" , "9anime Companion" ) ; $ ( "#nac__toast__open-changelog" ) . on ( "click" , ( ) => { chrome . runtime . sendMessage ( { intent : 0 , params : { goto : "Changelog" , } , } ) ; } ) ; } ; let EnableAdblockToast = ( ) => { toastr . info ( "Looks like \"Remove ads\" is not turned on. Be sure to enable it from settings.<br>" + "<button class='nac__toast-btn' id='nac__toast__open-settings'>Open Settings</button>" , "9anime Companion" ) ; $ ( "#nac__toast__open-settings" ) . on ( "click" , ( ) => { chrome . runtime . sendMessage ( { intent : Intent . Open_Options , } ) ; } ) ; } ; chrome . runtime . sendMessage ( { intent : Intent . Install_Check , } , ( response ) => { if ( response . success && response . data ) { switch ( response . data . type ) { case "update" : changelogToast ( response . data . versionName ) ; break ; case "install" : loadSettings ( "remAds" ) . then ( settings => { if ( ! settings . remAds ) { EnableAdblockToast ( ) ; } } ) ; break ; default : break ; } } } ) ; chrome . runtime . onMessage . addListener ( ( message ) => { switch ( message . intent ) { case Intent . Show_Notification : toastr . success ( message . message , message . title ) ; break ; default : break ; } } ) ;