Your search doesn't appear to be related to our current research interests.
+Please try adjusting your search or contact us for further support.
+ `; } + // Add content for allowing user to take action if search isn't relevant + // User can try again by doing an exact search or create a report + htmlToInject += ` ++ If this information shown above isn't relevant to your search, please try reloading with an exact search match. +
++ You can also try limiting which topics are included. Untick a topic and click Reload to try again without these topics:`; + for (var i = 0; i < data.topics.length; i++){ + let topic = data.topics[i]; + let checked = ' checked'; + if (topic['excluded'] == 1) checked = '' + htmlToInject += `
+ If the information shown still isn't relevant to your search, please report this to us so that we can work to improve the accuracy of this tool. +
+Your search doesn't appear to be related to our current research interests.
-Please try adjusting your search or contact us for further support.
+There's been an error when trying to connect to the server.
+Please try again or contact us for support if the problem persists.
`); - } - }).fail(function(){ - // If the get request fails, display an appropriate message to user - container.append(` -There's been an error when trying to connect to the server.
-Please try again or contact us for support if the problem persists.
- `); - }); + }); - } - // If not on a valid Google search results page - else { - container.html(` -You're not currently on a Google search results page.
-To use this extension please perform a Google search and then load this extension again.
` - ); - } - })(); + } + // If not on a valid Google search results page + else { + container.html(` +You're not currently on a Google search results page.
+To use this extension please perform a Google search and then load this extension again.
` + ); + } + })(); + } + // Load content on popup start + loadMainContent(); + + // User clicks "not relevant" exact search button: + // Reloads search using 'exact search' that will only match the entire search term, not words within it + $('body').on('click', '#notrelevanttoggle', function(){ + $('#notrelevant').toggle(); + }); + + // User clicks "not relevant" exact search button: + // Reloads search using 'exact search' that will only match the entire search term, not words within it + $('body').on('click', '#notrelevant-exactsearch', function(){ + searchExact = 1; + loadMainContent(); + }); + + // User clicks the "not relevant" topic reload button: + // Reloads search and excludes any unticked topics + $('body').on('click', '#notrelevant-topic-reload', function(){ + topicsExclude = $(".notrelevant-topic input:checkbox:not(:checked)").map(function(){return $(this).val();}).get().join(','); + loadMainContent(); + }); + + // User clicks the "not relevant" report post button: + // Sends report to API + $('body').on('click', '#notrelevant-report', function(){ + $.post(apiUrlNotRelevantReportPost, {user_search_query: userSearchQuery, active_prompt_id: activePromptId}, function(data, status){ + if (data.report_saved == 1){ + container.html('There's been an error when trying to send your report to the server.
+Please try again or contact us for support if the problem persists.
+ `); + }); + }); - // User clicks the response post button: sends response to API + // User clicks the response post button: + // Sends response to API $('body').on('click', '#response-post-button', function(){ let responseContent = $('#response-content').val(); if (responseContent.length > 0){ // Post the response - $.post(apiUrlPromptPost, {user_response_content: responseContent, active_prompt_id: activePromptId}, function(data, status){ + $.post(apiUrlResponsePost, {user_response_content: responseContent, active_prompt_id: activePromptId}, function(data, status){ if (data.response_saved == 1){ - container.html('