Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save cuylerstuwe/3cc3932b96dd32123be5bdf98b6e41a2 to your computer and use it in GitHub Desktop.

Select an option

Save cuylerstuwe/3cc3932b96dd32123be5bdf98b6e41a2 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Fast Interest Audit
// @namespace salembeats
// @version 5.0
// @description Fast Interest Audits - Minor refactor.
// @author Cuyler Stuwe (salembeats)
// @include *
// @icon https://i.imgur.com/snRSm80.gif
// @grant none
// ==/UserScript==
const IMAGE_HEIGHT_PX = 400;
const IMAGE_MAX_WIDTH_PX = 400;
const BUTTON_HOLDER_WIDTH_PX = 500;
const HEADLINE_POSITION_PX_X = 20;
const HEADLINE_POSITION_PX_Y = 50;
const IMAGE_POSITION_PX_X = 20;
const IMAGE_POSITION_PX_Y = 150;
const PRODUCT_DESCRIPTION_POSITION_PX_X = 440;
const PRODUCT_DESCRIPTION_POSITION_PX_Y = 150;
const BUTTON_HOLDER_POSITION_PX_X = 440;
const BUTTON_HOLDER_POSITION_PX_Y = 250;
const HEADLINE_FONT_SIZE = "5.0em";
const RADIO_BUTTON_LABEL_FONT_SIZE = "2.0em";
const RADIO_BUTTON_SCALE = 4;
const RADIO_BUTTON_EXTRA_LEFT_PADDING_PX = 30;
const HIGHLIGHT_COLOR = "yellow";
const LOWLIGHT_COLOR = "gray";
const BACKGROUND_COLOR = "black";
const DEFAULT_TEXT_COLOR = "white";
const RADIO_BUTTON_YES_COLOR = "green";
const RADIO_BUTTON_NO_COLOR = "red";
if(window === window.top) {return;}
var instructionsDiv = document.querySelector(".panel.panel-primary");
if(!instructionsDiv) {return;}
var interestAuditLanguagePairs = {
"is the item relevant to the interest": "English",
"ist der artikel für das interesse relevant": "German",
"il prodotto e’ rilevante all’interesse": "Italian",
"es el artículo relevante al interés": "Spanish",
"is het artikel relevant voor de interesse": "Dutch",
"le produit est": "French",
"その商品は特定のインタレスト (興味関心) に対して関連性があるか": "Japanese",
"o item é relevante para o interesse": "Portuguese",
"商品是否与给定兴趣相关": "Chinese",
};
var interestAuditTriggers = Object.keys(interestAuditLanguagePairs);
function getInterestAuditLanguage()
{
let instructionsText = instructionsDiv.textContent;
let instructionsTextLowercase = instructionsText.toLowerCase();
for(const triggerPhrase of interestAuditTriggers) {
console.log(triggerPhrase);
if(instructionsTextLowercase.includes(triggerPhrase)) {return interestAuditLanguagePairs[triggerPhrase];}
if(instructionsText.includes(triggerPhrase)) {return interestAuditLanguagePairs[triggerPhrase];}
console.log("NOT " + triggerPhrase);
}
return "";
}
function moveToFixedSpot(item, x, y) {
item.style.position = "static";
item.style.left = x;
item.style.top = y;
}
function stripToBareInterestQuestion(originalQuestion) {
return originalQuestion
.replace(/Interest/,"")
.replace(/Intérêt/,"")
.replace(/インタレスト名/,"")
.replace(/Interesse/,"")
.replace(/兴趣/,"")
.replace(/Interés/, "")
.replace(/:\s/, "")
.replace(/(.*)/, "$&?").toUpperCase();
}
function hideBody() {
document.body.style.display = "none";
}
function showBody() {
document.body.style.display = "block";
}
function insertStyleToHideBoldSpans() {
document.body.innerHTML += `
<style>
span[style*='bold'] {
display: none;
}
</style>
`;
}
function main(language) {
hideBody();
const fullInterestParagraph = document.querySelector("p[style='font-size:1.4em; font-weight:bold;']");
const redTextParagraphs = document.querySelectorAll("p[style='font-size:1.0em; font-weight:bold; color:red;']");
const otherRedTextParagraphs = document.querySelectorAll("span[style*='FF0000']");
const productImage = document.querySelector("img[border='0']");
const productDescriptionDiv = document.querySelector("div[style='font-style: italic; font-weight: bold; max-width: 300px; padding-bottom:15px;']");
const yesButton = document.querySelector("#radio-yes");
const yesButtonLabel = document.querySelector("label[for='radio-yes']") ||
document.querySelector("#radio-yes~*");
const noButton = document.querySelector("#radio-no");
const noButtonLabel = document.querySelector("label[for='radio-no']") ||
document.querySelector("#radio-no~*");
const skipButton = document.querySelector("#radio-skip");
const skipButtonLabel = document.querySelector("label[for='radio-skip']") ||
document.querySelector("#radio-skip~*");
const skipButtonNumberSpan = document.querySelector("label[for='radio-skip']~span");
const buttonsHolder = document.querySelector("div[style='float:left; width:275px; padding-left:20px;']") ||
document.querySelector("div[style='float:left; width:325px; padding-left:20px;']");
const commentsText = document.querySelector("#comments");
const miscBoldDivs = document.querySelectorAll("div[style='font-weight:bold;']");
const miscBoldSpans = document.querySelectorAll("span[style*='bold']");
const allParagraphs = document.querySelectorAll("p");
const hitBody = document.querySelector("body");
const hitSubmitButton = document.querySelector("[type='submit']");
let redundantButtonAreaText;
if(buttonsHolder) {
redundantButtonAreaText = buttonsHolder.querySelector("p:first-of-type");
}
if(redundantButtonAreaText) { redundantButtonAreaText.style.display = "none"; }
if(skipButtonNumberSpan) { skipButtonNumberSpan.style.display = "none"; }
hitBody.style.backgroundColor = BACKGROUND_COLOR;
hitBody.style.color = DEFAULT_TEXT_COLOR;
fullInterestParagraph.style.color = HIGHLIGHT_COLOR;
productDescriptionDiv.style.color = LOWLIGHT_COLOR;
productImage.style.height = `${IMAGE_HEIGHT_PX}px`;
productImage.style.maxWidth = `${IMAGE_MAX_WIDTH_PX}px`;
instructionsDiv.style.display = "none";
fullInterestParagraph.textContent = stripToBareInterestQuestion(fullInterestParagraph.textContent);
fullInterestParagraph.style.fontSize = HEADLINE_FONT_SIZE;
for(const redTextParagraph of redTextParagraphs) { redTextParagraph.style.display = "none"; }
for(const redTextParagraph of otherRedTextParagraphs) { redTextParagraph.style.display = "none"; }
for(const boldDiv of miscBoldDivs) { boldDiv.style.display = "none"; }
for(const span of miscBoldSpans) { span.style.display = "none"; }
if(yesButtonLabel) {
yesButtonLabel.innerText = "YES!";
yesButtonLabel.style.color = RADIO_BUTTON_YES_COLOR;
yesButtonLabel.style.paddingLeft = `${RADIO_BUTTON_EXTRA_LEFT_PADDING_PX}px`;
yesButtonLabel.style.fontSize = RADIO_BUTTON_LABEL_FONT_SIZE;
}
if(noButtonLabel) {
noButtonLabel.textContent = "NO.";
noButtonLabel.style.color = RADIO_BUTTON_NO_COLOR;
noButtonLabel.style.paddingLeft = `${RADIO_BUTTON_EXTRA_LEFT_PADDING_PX}px`;
noButtonLabel.style.fontSize = RADIO_BUTTON_LABEL_FONT_SIZE;
}
if(buttonsHolder) { buttonsHolder.style.width = `${BUTTON_HOLDER_WIDTH_PX}px`; }
if(yesButton) { yesButton.style.transform = `scale(${RADIO_BUTTON_SCALE})`; }
if(noButton) { noButton.style.transform = `scale(${RADIO_BUTTON_SCALE})`; }
if(skipButton) { skipButton.style.display = "none"; }
if(skipButtonLabel) { skipButtonLabel.style.display = "none"; }
if(commentsText) { commentsText.style.display = "none"; }
if(fullInterestParagraph) {
moveToFixedSpot(fullInterestParagraph,
`${HEADLINE_POSITION_PX_X}px`,
`${HEADLINE_POSITION_PX_Y}px`);
}
if(productImage) {
moveToFixedSpot(productImage,
`${IMAGE_POSITION_PX_X}px`,
`${IMAGE_POSITION_PX_Y}px`);
}
if(productDescriptionDiv) {
moveToFixedSpot(productDescriptionDiv,
`${PRODUCT_DESCRIPTION_POSITION_PX_X}px`,
`${PRODUCT_DESCRIPTION_POSITION_PX_Y}px`);
}
if(buttonsHolder) {
moveToFixedSpot(buttonsHolder,
`${BUTTON_HOLDER_POSITION_PX_X}px`,
`${BUTTON_HOLDER_POSITION_PX_Y}px`);
}
yesButton.addEventListener("click",function() {
hitSubmitButton.click();
});
noButton.addEventListener("click",function() {
hitSubmitButton.click();
});
insertStyleToHideBoldSpans();
showBody();
}
let language = getInterestAuditLanguage();
if(language)
{
main(language);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment