2024-09-30 15:15:08 +01:00
browser . runtime . onMessage . addListener ( ( message ) => {
2024-09-11 18:11:44 +01:00
if ( message . type === "MY_GET_URL_R" ) {
window . postMessage ( message ) ;
2024-09-29 11:45:53 +01:00
} else if ( message . type === "GET_DATA_FROM_PAGE" ) {
2024-10-03 14:10:09 +01:00
// Parse things for linkedin
if ( window . location . host . includes ( "linkedin" ) ) {
if ( window . location . host . includes ( "merchantpool1" ) ) {
return ;
}
const jobTitle = document . querySelector ( 'h1' ) . textContent ;
const company = document . querySelector ( '.relative a[target="_self"]' ) . textContent ;
const money = document . querySelector ( 'ul li div div div li-icon[type="job"]' ) ? . parentNode ? . parentNode ? . parentNode ? . parentNode ? . children [ 1 ] ? . children [ 0 ] ? . textContent ? . replaceAll ( /\s{2,}/g , '' ) ? ? '' ;
const description = document . querySelector ( 'article' ) . textContent ;
browser . runtime . sendMessage ( { type : "GOT_INFO_R" , company , jobTitle , money , description } ) ;
return ;
}
// Ignore everything that is no glassdoor
if ( ! window . location . host . includes ( "glassdoor" ) ) return ;
2024-10-02 10:33:46 +01:00
const company = document . querySelector ( 'header[data-test="job-details-header"]' )
2024-09-29 11:45:53 +01:00
. children [ 0 ] . children [ 0 ] . querySelector ( "h4" ) . innerHTML ;
2024-09-30 15:15:08 +01:00
const jobTitle = document
2024-09-29 11:45:53 +01:00
. querySelector ( 'header[data-test="job-details-header"]' )
. querySelector ( "h1" ) . innerHTML ;
2024-09-30 15:15:08 +01:00
2024-10-02 10:33:46 +01:00
const description = [ ... document . querySelector ( 'header[data-test="job-details-header"]' ) . parentNode . querySelectorAll ( 'button' ) ] . filter ( a => a . textContent == "Show more" ) [ 0 ] ? . parentNode ? . parentNode ? . textContent ;
2024-09-30 15:15:08 +01:00
let money = ""
const moneySectionNode = document . querySelector ( 'section>section' ) ;
if ( moneySectionNode && [ "Base pay range" , "Base pay" ] . includes ( moneySectionNode . querySelector ( 'h2' ) . textContent ) ) {
money = moneySectionNode . querySelector ( "div>div>div" ) . children [ 1 ] ? . textContent ? ? ''
}
2024-10-02 10:33:46 +01:00
browser . runtime . sendMessage ( { type : "GOT_INFO_R" , company , jobTitle , money , description } ) ;
2024-09-29 11:45:53 +01:00
} else if ( message . type === "GOT_INFO_R" ) {
window . postMessage ( message ) ;
2024-09-11 18:11:44 +01:00
}
} ) ;
2024-09-30 15:15:08 +01:00
window . addEventListener ( "message" , ( e ) => {
2024-09-11 18:11:44 +01:00
if ( e . data . type === "MY_GET_URL" ) {
browser . runtime . sendMessage ( { type : "MY_GET_URL" } ) ;
} else if ( e . data . type === "HAS_EXTENSION_Q" ) {
window . postMessage ( { type : "HAS_EXTENSION" } ) ;
2024-09-29 11:45:53 +01:00
} else if ( e . data . type === "REGISTER_INTEREST" ) {
browser . runtime . sendMessage ( { type : "REGISTER_INTEREST" } ) ;
2024-10-03 14:10:09 +01:00
} else if ( e . data . type === "R_GET_DATA_FROM_PAGE" ) {
browser . runtime . sendMessage ( { type : "R_GET_DATA_FROM_PAGE" } ) ;
}
2024-09-11 18:11:44 +01:00
} ) ;