').addClass(tagsPreviewThreadCls).addClass(tagsContainerCls).attr('data-preview', 'true'))
;
getSettingsModalContent().append(wrapper);
}
const coPilotNewThreadAutoSubmitCheckboxId = 'coPilotNewThreadAutoSubmit';
const getCoPilotNewThreadAutoSubmitCheckbox = () => $i(coPilotNewThreadAutoSubmitCheckboxId);
const coPilotRepeatLastAutoSubmitCheckboxId = 'coPilotRepeatLastAutoSubmit';
const getCoPilotRepeatLastAutoSubmitCheckbox = () => $i(coPilotRepeatLastAutoSubmitCheckboxId);
const hideSideMenuCheckboxId = 'hideSideMenu';
const getHideSideMenuCheckbox = () => $i(hideSideMenuCheckboxId);
const tagsTextAreaId = 'tagsText';
const getTagsTextArea = () => $i(tagsTextAreaId);
const tagColorPickerId = genCssName('tagColorPicker');
const getTagColorPicker = () => $i(tagColorPickerId);
const enableDebugCheckboxId = genCssName('enableDebug');
const getEnableDebugCheckbox = () => $i(enableDebugCheckboxId);
const copyTextToClipboard = async text => {
try {
await navigator.clipboard.writeText(text);
console.log('Text copied to clipboard', {text});
} catch (err) {
console.error('Failed to copy text: ', err);
}
};
const genColorPart = color => `
`;
function handleSettingsInit() {
const modalExists = getPerplexityHelperModal().length > 0;
const firstCheckboxExists = getCoPilotNewThreadAutoSubmitCheckbox().length > 0;
if (!modalExists || firstCheckboxExists) { return; }
const insertSeparator = () => getSettingsModalContent().append('
');
createCheckbox(coPilotNewThreadAutoSubmitCheckboxId, 'Auto Submit New Thread With CoPilot', saveConfigFromForm);
createCheckbox(coPilotRepeatLastAutoSubmitCheckboxId, 'Auto Submit Repeat With CoPilot', saveConfigFromForm);
createCheckbox(hideSideMenuCheckboxId, 'Hide Side Menu', saveConfigFromForm);
insertSeparator();
createTextArea(tagsTextAreaId, 'Tags', saveConfigFromForm, tagsHelpText).prop('rows', 5).css('min-width', '700px').prop('wrap', 'off');
createPaletteLegend();
createColorInput(tagColorPickerId, 'Custom color - copy field for tag to clipboard:', () => {
const color = getTagColorPicker().val();
debugLog('color', color);
copyTextToClipboard(genColorPart(color));
});
createTagsPreview();
insertSeparator();
createCheckbox(enableDebugCheckboxId, 'Enable Debug', saveConfigFromForm);
const savedStates = JSON.parse(localStorage.getItem(storageKey));
if (savedStates === null) { return; }
getCoPilotNewThreadAutoSubmitCheckbox().prop('checked', savedStates.coPilotNewThreadAutoSubmit);
getCoPilotRepeatLastAutoSubmitCheckbox().prop('checked', savedStates.coPilotRepeatLastAutoSubmit);
getHideSideMenuCheckbox().prop('checked', savedStates.hideSideMenu);
getTagsTextArea().val(savedStates.tagsText);
getEnableDebugCheckbox().prop('checked', savedStates.enableDebug);
}
debugLog(jq.fn.jquery);
const getSavedStates = () => JSON.parse(localStorage.getItem(storageKey));
const getModal = () => jq("[data-testid='quick-search-modal'] > div");
const getCopilotToggleButton = textarea => textarea.parent().parent().find('[data-testid="copilot-toggle"]');
const upperControls = () => jq('svg[data-icon="plus"]').parent().parent().parent().parent().first();
const getControlsArea = () => jq('textarea[placeholder="Ask follow-up"]').parent().parent().children().last();
const getCopilotNewThreadButton = () => jq('#copilot_new_thread');
const getCopilotRepeatLastButton = () => jq('#copilot_repeat_last');
const getSelectAllButton = () => jq('#perplexity_helper_select_all');
const getSelectAllAndSubmitButton = () => jq('#perplexity_helper_select_all_and_submit');
const getCopyPlaceholder = () => jq('#perplexity_helper_copy_placeholder');
const getCopyAndFillInPlaceholder = () => jq('#perplexity_helper_copy_placeholder_and_fill_in');
const getTopSettingsButtonEl = () => $i(topSettingsButtonId);
const getLeftSettingsButtonEl = () => $i(leftSettingsButtonId);
const getSideMenu = () => jq('.min-h-\\[100vh\\]').children().first();
const getSettingsModalContent = () => getPerplexityHelperModal().find('.modal-content');
const getSubmitBtn0 = () => jq('svg[data-icon="arrow-up"]').last().parent().parent();
const getSubmitBtn1 = () => jq('svg[data-icon="arrow-right"]').last().parent().parent();
const getSubmitBtn2 = () => jq('svg[data-icon="code-fork"]').last().parent().parent();
const isStandardControlsAreaFc = () => !getControlsArea().hasClass('bottom-0');
const getCurrentControlsArea = () => isStandardControlsAreaFc() ? getControlsArea() : getControlsArea().find('.bottom-0');
const getDashedCheckboxButton = () => jq('svg[data-icon="square-dashed"]').parent().parent();
const getStarSVG = () => jq('svg[data-icon="star-christmas"]');
const getSpecifyQuestionBox = () => jq('svg[data-icon="star-christmas"]').parent().parent().parent().last();
const getNumberOfDashedSVGs = () => getSpecifyQuestionBox().find('svg[data-icon="square-dashed"]').length;
const getSpecifyQuestionControlsWrapper = () => getSpecifyQuestionBox().find('button:contains("Continue")').parent()
const getCopiedModal = () => jq('#copied-modal');
const getCopiedModal2 = () => jq('#copied-modal-2');
const getCopyPlaceholderInput = () => getSpecifyQuestionBox().find('textarea');
const getSubmitButton0or2 = () => getSubmitBtn0().length < 1 ? getSubmitBtn2() : getSubmitBtn0();
const questionBoxWithPlaceholderExists = () => getSpecifyQuestionBox().find('textarea')?.attr('placeholder')?.length > 0 ?? false;
const selectAllCheckboxes = () => {
const currentCheckboxes = getDashedCheckboxButton();
debugLog('checkboxes', currentCheckboxes);
const removeLastObject = (arr) => {
if (!_.isEmpty(arr)) {
debugLog('arr', arr);
const newArr = _.dropRight(arr, 1);
debugLog("newArr", newArr);
getDashedCheckboxButton().last().click();
return setTimeout(() => {
removeLastObject(newArr)
}, 1)
}
};
removeLastObject(currentCheckboxes);
}
const isCopilotOn = (el) => el.hasClass('text-super')
const toggleBtnDot = (btnDot, value) => {
debugLog(' toggleBtnDot btnDot', btnDot);
const btnDotInner = btnDot.find('.rounded-full');
debugLog('btnDotInner', btnDotInner);
if (!btnDotInner.hasClass('bg-super') && value === true) {
btnDot.click();
}
}
const checkForCopilotToggleState = (timer, checkCondition, submitWhenTrue, submitButtonVersion) => {
debugLog("checkForCopilotToggleState run", timer, checkCondition(), submitWhenTrue, submitButtonVersion);
if (checkCondition()) {
clearInterval(timer);
debugLog("checkForCopilotToggleState condition met, interval cleared");
const submitBtn = submitButtonVersion === 0 ? getSubmitButton0or2() : getSubmitBtn1();
debugLog('submitBtn', submitBtn);
if (submitWhenTrue) {
submitBtn.click();
}
}
}
const openNewThreadModal = (lastQuery) => {
debugLog('openNewThreadModal', lastQuery)
const newThreadText = jq(".sticky div").filter(function () {
return /^New Thread$/i.test(jq(this).text());
});
if (!newThreadText.length) {
debugLog('newThreadText.length should be 1', newThreadText.length);
return;
}
debugLog('newThreadText', newThreadText);
newThreadText.click();
setTimeout(() => {
debugLog('newThreadText.click()');
const modal = getModal();
if (modal.length > 0) {
const textArea = modal.find('textarea');
if (textArea.length !== 1) debugLog('textArea.length should be 1', textArea.length);
const newTextArea = textArea.last();
const textareaElement = newTextArea[0];
debugLog('textareaElement', textareaElement);
changeValueUsingEvent(textareaElement, lastQuery);
const copilotButton = getCopilotToggleButton(newTextArea);
toggleBtnDot(copilotButton, true);
const isCopilotOnBtn = () => isCopilotOn(copilotButton);
const coPilotNewThreadAutoSubmit =
getSavedStates()
? getSavedStates().coPilotNewThreadAutoSubmit
: getCoPilotNewThreadAutoSubmitCheckbox().prop('checked');
const copilotCheck = () => {
const ctx = {timer: null};
ctx.timer = setInterval(() => checkForCopilotToggleState(ctx.timer, isCopilotOnBtn, coPilotNewThreadAutoSubmit, 1), 500);
}
copilotCheck();
} else {
debugLog('else of modal.length > 0');
}
},
2000);
}
const getLastQuery = () => {
// wrapper around prompt + response
const lastQueryBox = jq('svg[data-icon="repeat"]').last().nthParent(7);
if (lastQueryBox.length === 0) {
debugLog('lastQueryBox not found');
}
const wasCopilotUsed = lastQueryBox.find('svg[data-icon="star-christmas"]').length > 0;
const lastQueryBoxText = lastQueryBox.find('.whitespace-pre-line').text();
debugLog('[getLastQuery]', {lastQueryBox, wasCopilotUsed, lastQueryBoxText});
return lastQueryBoxText ?? null;
}
const saveConfigFromForm = () => {
const checkBoxStates = {
coPilotNewThreadAutoSubmit: getCoPilotNewThreadAutoSubmitCheckbox().prop('checked'),
coPilotRepeatLastAutoSubmit: getCoPilotRepeatLastAutoSubmitCheckbox().prop('checked'),
hideSideMenu: getHideSideMenuCheckbox().prop('checked'),
tagsText: getTagsTextArea().val(),
enableDebug: getEnableDebugCheckbox().prop('checked'),
};
saveConfig(checkBoxStates);
};
const showPerplexityHelperModal = () => {
getPerplexityHelperModal().show().css('display', 'flex');
}
const hidePerplexityHelperModal = () => {
getPerplexityHelperModal().hide();
}
const handleTopSettingsButtonInsertion = () => {
const copilotHelperSettings = getTopSettingsButtonEl();
debugLog('upperControls().length > 0', upperControls().length, 'copilotHelperSettings.length', copilotHelperSettings.length, 'upperControls().children().length', upperControls().children().length);
if (upperControls().length > 0 && copilotHelperSettings.length < 1 && upperControls().children().length >= 1) {
debugLog('inserting settings button');
upperControls().children().eq(0).after(upperButton(topSettingsButtonId, cogIco, "perplexity_helper_settings"));
}
};
const handleTopSettingsButtonSetup = () => {
const settingsButtonEl = getTopSettingsButtonEl();
if (settingsButtonEl.length === 1 && !settingsButtonEl.attr('data-has-custom-click-event')) {
debugLog('handleTopSettingsButtonSetup: setting up the button');
if (settingsButtonEl.length === 0) {
debugLog('handleTopSettingsButtonSetup: settingsButtonEl.length === 0');
}
settingsButtonEl.on("click", () => {
debugLog('perplexity_helper_settings open click');
showPerplexityHelperModal();
});
settingsButtonEl.attr('data-has-custom-click-event', true);
}
};
const applySideMenuHiding = () => {
const sideMenu = getSideMenu();
if (getSavedStates()) getSavedStates().hideSideMenu || getHideSideMenuCheckbox().prop('checked') ? sideMenu.hide() : sideMenu.show();
};
const handleModalCreation = () => {
if (getPerplexityHelperModal().length > 0) return;
debugLog('handleModalCreation: creating modal');
jq("body").append(modalHTML);
getPerplexityHelperModal().find('.close').on('click', () => {
debugLog('perplexity_helper_settings close click');
hidePerplexityHelperModal();
});
};
const getLeftPanel = () => jq('svg[data-icon="rectangle-vertical-history"]').parent().parent().parent().parent().parent().parent();
const handleLeftSettingsButtonSetup = () => {
if (getLeftSettingsButtonEl().length === 1) return;
const leftPanel = getLeftPanel();
if (leftPanel.length === 0) {
debugLog('handleLeftSettingsButtonSetup: leftPanel not found');
}
const wrapperEl = jq('')
.addClass('flex items-center')
.css({ paddingRight: '0.3em', justifyContent: 'right' })
;
const iconEl = jq('svg[data-icon="gear"]').parent().clone();
const btnEl = jq('