Write a userscript that adds a "Jump to recipe" button at the top of the page
Assistant
Sure, I can help you write a userscript that accomplishes this. Userscripts are scripts that run in your browser to add functionality to webpages. They're usually written in JavaScript and require a userscript manager extension like Tampermonkey or Greasemonkey.
Here's an example of what your userscript could look like:
javascriptCopy code// ==UserScript==
// @name Jump to Recipe
// @namespace
// @version 0.1
// @description Adds a "Jump to Recipe" button on Serious Eats pages
// @author You
// @match
// @grant none
// ==/UserScript==
(function() {
'use strict';
code
// Create the "Jump to Recipe" button
let button = document.createElement('button');
button.innerText = 'Jump to Recipe';
button.style.position = 'fixed';
button.style.top = '10px';
button.style.right = '10px';
button.style.zIndex = 1000; // Ensure the button is above other elements
button.onclick = function() {
// Find the recipe element
let recipe = document.querySelector('.recipe-wrapper');
if (recipe) {
// Scroll to the recipe
<URL>rollIntoView({behavior: 'smooth'});
}
};
// Add the button to the page
document.body.appendChild(button);
})();
This userscript creates a "Jump to Recipe" button that, when clicked, scrolls the page to the recipe (if it can find one). It is set to run on all pages on the
Please note that this is a simple script and may not work perfectly on all pages or with all layouts. It assumes that the recipe is contained within an element with the classrecipe-wrapper, which may not be the case on all Serious Eats pages. If you want to improve the script, you could add error handling or make the script more adaptable to different page layouts.
Also, keep in mind that you need to install a userscript manager like Tampermonkey or Greasemonkey to use this script. And always be careful when installing userscripts, as they can potentially be malicious. Only install scripts from sources you trust.
User
The recipe element has an id "structured-project-content_1-0"
Assistant
Thanks for providing the ID of the recipe element. We can update the userscript accordingly.
javascriptCopy code// ==UserScript==
// @name Jump to Recipe
// @namespace
// @version 0.1
// @description Adds a "Jump to Recipe" button on Serious Eats pages
// @author You
// @match
// @grant none
// ==/UserScript==
(function() {
'use strict';
code
// Create the "Jump to Recipe" button
let button = document.createElement('button');
button.innerText = 'Jump to Recipe';
button.style.position = 'fixed';
button.style.top = '10px';
button.style.right = '10px';
button.style.zIndex = 1000; // Ensure the button is above other elements
button.onclick = function() {
// Find the recipe element
let recipe = document.querySelector('#structured-project-content_1-0');
if (recipe) {
// Scroll to the recipe
<URL>rollIntoView({behavior: 'smooth'});
}
};
// Add the button to the page
document.body.appendChild(button);
})();
This version of the script usesdocument.querySelector('#structured-project-content_1-0')to find the recipe element by its ID, instead of by its class. The rest of the script is the same.
Remember to add this script to your userscript manager (like Tampermonkey or Greasemonkey) in order to use it.
User
This script jumps forward slightly too far
Assistant
The issue might be due to the page's header or other elements obscuring part of the recipe when scrolling. One way to address this is by adjusting the scroll position a bit after scrolling to the recipe. Here's an updated version of your userscript:
javascriptCopy code// ==UserScript==
// @name Jump to Recipe
// @namespace
// @version 0.1
// @description Adds a "Jump to Recipe" button on Serious Eats pages
// @author You
// @match
// @grant none
// ==/UserScript==
(function() {
'use strict';
code
// Create the "Jump to Recipe" button
let button = document.createElement('button');
button.innerText = 'Jump to Recipe';
button.style.position = 'fixed';
button.style.top = '10px';
button.style.right = '10px';
button.style.zIndex = 1000; // Ensure the button is above other elements
button.onclick = function() {
// Find the recipe element
let recipe = document.querySelector('#structured-project-content_1-0');
if (recipe) {
// Scroll to the recipe
<URL>rollIntoView({behavior: 'smooth'});
// Adjust scroll position
window.scrollBy(0, -100); // Adjust this value as needed
}
};
// Add the button to the page
document.body.appendChild(button);
})();
In this version of the script,window.scrollBy(0, -100);adjusts the scroll position by moving upwards by 100 pixels after scrolling to the recipe. You can adjust the value-100as needed to fit the layout of the page.
If the issue persists, you might need to make more significant changes to the script to account for the layout of the page.
User
how can I add sleep
Assistant
In JavaScript, you can simulate a sleep or delay function by using thesetTimeoutfunction, which executes a function or specified piece of code once the timer expires. Here's how you can modify your script to add a delay before adjusting the scroll position:
javascriptCopy code// ==UserScript==
// @name Jump to Recipe
// @namespace
// @version 0.1
// @description Adds a "Jump to Recipe" button on Serious Eats pages
// @author You
// @match
// @grant none
// ==/UserScript==
(function() {
'use strict';
code
// Create the "Jump to Recipe" button
let button = document.createElement('button');
button.innerText = 'Jump to Recipe';
button.style.position = 'fixed';
button.style.top = '10px';
button.style.right = '10px';
button.style.zIndex = 1000; // Ensure the button is above other elements
button.onclick = function() {
// Find the recipe element
let recipe = document.querySelector('#structured-project-content_1-0');
if (recipe) {
// Scroll to the recipe
<URL>rollIntoView({behavior: 'smooth'});
// Add a delay before adjusting scroll position
setTimeout(function() {
window.scrollBy(0, -100); // Adjust this value as needed
}, 500); // Delay in milliseconds
}
};
// Add the button to the page
document.body.appendChild(button);
})();
In this version of the script,setTimeoutis used to add a delay of 500 milliseconds (half a second) before adjusting the scroll position. You can change the500value to increase or decrease the delay as needed. Remember that the delay is in milliseconds, so 1000 milliseconds is equal to 1 second.
User
// ==UserScript==
// @name Jump to Recipe - Serious Eats
// @namespace
// @version 0.1
// @description Adds a "Jump to Recipe" button on Serious Eats pages
// @author You
// @match
// @grant none
// ==/UserScript==
(function() {
'use strict';
code
// Create the "Jump to Recipe" button
let button = document.createElement('button');
button.innerText = 'Jump to Recipe';
button.style.position = 'fixed';
button.style.top = '10px';
button.style.right = '10px';
button.style.zIndex = 1000; // Ensure the button is above other elements
button.onclick = function() {
// Find the recipe element
let recipe = document.querySelector('#structured-project-content_1-0');
if (recipe) {
// Scroll to the recipe
<URL>rollIntoView({behavior: 'smooth'});
// Adjust scroll position
setTimeout(function() {
window.scrollBy(0, -100); // Adjust this value as needed
}, 1000); // Delay in milliseconds
}
};
// Add the button to the page
document.body.appendChild(button);
})();
Modify this script to move the jump to recipe button above the element with id "heading_1-0". Also make it bigger
Assistant
In order to move the "Jump to Recipe" button above the element with the ID "heading_1-0", we will need to insert the button as a sibling before that element. We can do this using theinsertBeforemethod. To make the button bigger, we can adjust itsfontSize,padding, andborderRadiusstyles.
javascriptCopy code// ==UserScript==
// @name Jump to Recipe - Serious Eats
// @namespace
// @version 0.1
// @description Adds a "Jump to Recipe" button on Serious Eats pages
// @author You
// @match
// @grant none
// ==/UserScript==
(function() {
'use strict';
code
// Create the "Jump to Recipe" button
let button = document.createElement('button');
button.innerText = 'Jump to Recipe';
button.style.fontSize = '20px'; // Increase the font size
button.style.padding = '10px 20px'; // Add some padding
button.style.borderRadius = '5px'; // Round the corners
button.onclick = function() {
// Find the recipe element
let recipe = document.querySelector('#structured-project-content_1-0');
if (recipe) {
// Scroll to the recipe
<URL>rollIntoView({behavior: 'smooth'});
// Adjust scroll position
setTimeout(function() {
window.scrollBy(0, -100); // Adjust this value as needed
}, 1000); // Delay in milliseconds
}
};
// Find the heading element
let heading = document.querySelector('#heading_1-0');
if (heading) {
// Add the button to the page above the heading
<REDACTED>, heading);
} else {
// If the heading isn't found, add the button at the top of the body
<REDACTED>, document.body.firstChild);
}
})();
In this script, the button is first created and styled. Then, the script attempts to find the heading element. If it is found, the button is inserted before the heading. If the heading is not found, the button is inserted at the top of the body.
Please note that the appearance of the button may still be affected by the page's CSS. You may need to adjust the styles further to achieve the desired look.
javascriptCopy code// ==UserScript==
// @name Jump to Recipe - Serious Eats
// @namespace
// @version 0.1
// @description Adds a "Jump to Recipe" button on Serious Eats pages
// @author You
// @match
// @grant none
// ==/UserScript==
(function() {
'use strict';
code
// Create the "Jump to Recipe" button
let button = document.createElement('button');
button.innerText = 'Jump to Recipe';
button.style.display = 'flex';
button.style.margin = '0 1rem 0 0';
button.style.border = '1px solid #333';
button.style.borderRadius = '3px';
button.style.padding = '.375rem .5rem .25rem';
button.style.height = '2.5rem';
button.style.alignItems = 'center';
button.style.fontFamily = '"Space Grotesk", Helvetica, sans-serif';
button.style.fontSize = '1.125rem';
button.style.fontWeight = '600';
button.style.color = '#333';
button.style.lineHeight = '1.21';
button.style.letterSpacing = '-.01em';
button.style.textAlign = 'center';
button.style.textTransform = 'none';
button.style.background = '#fbf9ee';
button.style.boxShadow = '2px 2px 0 #26b7c5';
button.onclick = function() {
// Find the recipe element
let recipe = document.querySelector('#structured-project-content_1-0');
if (recipe) {
// Scroll to the recipe
<URL>rollIntoView({behavior: 'smooth'});
// Adjust scroll position
setTimeout(function() {
window.scrollBy(0, -100); // Adjust this value as needed
}, 1000); // Delay in milliseconds
}
};
// Find the heading element
let heading = document.querySelector('#heading_1-0');
if (heading) {
// Add the button to the page above the heading
<REDACTED>, heading);
} else {
// If the heading isn't found, add the button at the top of the body
<REDACTED>, document.body.firstChild);
}
User
I added the "setTimeout" function because if it is not there, the scrollBy interrupts the scrollIntoView and it doesnt scroll down all the way. Is there a cleaner less abrupt way to ensure it smoothly scrolls slightly above the element?
Assistant
To ensure a smooth scroll, instead of abruptly scrolling up after a delay, you could consider an alternative approach usingwindow.scrollTowith abehavior: 'smooth'option andElement.getBoundingClientRectto calculate the necessary scroll position.
This approach would scroll to a position a little above the target element, instead of scrolling to the element and then scrolling up.
javascriptCopy code// ==UserScript==
// @name Jump to Recipe - Serious Eats
// @namespace
// @version 0.1
// @description Adds a "Jump to Recipe" button on Serious Eats pages
// @author You
// @match
// @grant none
// ==/UserScript==
(function() {
'use strict';
code
// Create the "Jump to Recipe" button
let button = document.createElement('button');
button.innerText = 'Jump to Recipe';
button.style.display = 'flex';
button.style.margin = '0 1rem 0 0';
button.style.border = '1px solid #333';
button.style.borderRadius = '3px';
button.style.padding = '.375rem .5rem .25rem';
button.style.height = '2.5rem';
button.style.alignItems = 'center';
button.style.fontFamily = '"Space Grotesk", Helvetica, sans-serif';
button.style.fontSize = '1.125rem';
button.style.fontWeight = '600';
button.style.color = '#333';
button.style.lineHeight = '1.21';
button.style.letterSpacing = '-.01em';
button.style.textAlign = 'center';
button.style.textTransform = 'none';
button.style.background = '#fbf9ee';
button.style.boxShadow = '2px 2px 0 #26b7c5';
button.onclick = function() {
// Find the recipe element
let recipe = document.querySelector('#structured-project-content_1-0');
if (recipe) {
// Calculate the position to scroll to
let rect = recipe.getBoundingClientRect();
let scrollPos = window.pageYOffset + rect.top - 100; // Adjust this value as needed
// Smoothly scroll to the calculated position
window.scrollTo({ top: scrollPos, behavior: 'smooth' });
}
};
// Find the heading element
let heading = document.querySelector('#heading_1-0');
if (heading) {
// Add the button to the page above the heading
<REDACTED>, heading);
} else {
// If the heading isn't found, add the button at the top of the body
<REDACTED>, document.body.firstChild);
}
User
make the button slightly bigger and change it so it appears AFTER the title instead of before
Assistant
To adjust the size of the button, we can increase thefontSizeandpaddingCSS properties, which will effectively make the button larger. To make the button appear after the title, we can modify the script to insert the button after the heading element. We can use theinsertAdjacentElementmethod, which allows us to specify the position where the element should be inserted.
javascriptCopy code// ==UserScript==
// @name Jump to Recipe - Serious Eats
// @namespace
// @version 0.1
// @description Adds a "Jump to Recipe" button on Serious Eats pages
// @author You
// @match
// @grant none
// ==/UserScript==
(function() {
'use strict';
code
// Create the "Jump to Recipe" button
let button = document.createElement('button');
button.innerText = 'Jump to Recipe';
button.style.display = 'flex';
button.style.margin = '1rem 1rem 0 0'; // Increase vertical margin
button.style.border = '1px solid #333';
button.style.borderRadius = '3px';
button.style.padding = '.625rem .75rem .375rem'; // Increase padding
button.style.height = '3rem'; // Increase height
button.style.alignItems = 'center';
button.style.fontFamily = '"Space Grotesk", Helvetica, sans-serif';
button.style.fontSize = '1.5rem'; // Increase font size
button.style.fontWeight = '600';
button.style.color = '#333';
button.style.lineHeight = '1.21';
button.style.letterSpacing = '-.01em';
button.style.textAlign = 'center';
button.style.textTransform = 'none';
button.style.background = '#fbf9ee';
button.style.boxShadow = '2px 2px 0 #26b7c5';
button.onclick = function() {
// Find the recipe element
let recipe = document.querySelector('#structured-project-content_1-0');
if (recipe) {
// Calculate the position to scroll to
let rect = recipe.getBoundingClientRect();
let scrollPos = window.pageYOffset + rect.top - 100; // Adjust this value as needed
// Smoothly scroll to the calculated position
window.scrollTo({ top: scrollPos, behavior: 'smooth' });
}
};
// Find the heading element
let heading = document.querySelector('#heading_1-0');
if (heading) {
// Add the button to the page after the heading
heading.insertAdjacentElement('afterend', button);
} else {
// If the heading isn't found, add the button at the top of the body
<REDACTED>, document.body.firstChild);
}
“<URL> Write a userscript that adds a "Jump to recipe" button at the top of the page.” Conversation with gpt-4-browsing, from the ShareChat — Chatbot Conversations in the Wild dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m84vzv82qywk2nxavtkw3y5p
In this script, I've added the style properties from the.recipe-decision-block__buttons .relish-save-metaclass to the button'sstyleobject. This will style the "Jump to Recipe" button to look like the button in the provided CSS.
Please note that the appearance of the button may still be affected by the page's CSS. You may need to adjust the styles further to achieve the desired look. Also, the font "Space Grotesk" may not be available in all systems. If it's not, the browser will fall back to "Helvetica" or "sans-serif".
})();
In this script,Element.getBoundingClientRectis used to get the position of the recipe element relative to the viewport.window.pageYOffsetgives the number of pixels that the document is currently scrolled vertically. The result is the number of pixels from the top of the document to the top of the recipe element. Subtracting 100 from this value gives a position slightly above the recipe element.window.scrollTowith abehavior: 'smooth'option is then used to smoothly scroll to this position.
})();
In this script, I've increased thefontSize,padding,height, andmarginof the button to make it larger. I've also changed the script to use theinsertAdjacentElementmethod with the'afterend'position to insert the button after the heading element. If the heading is not found, the button is inserted at the top of the body as before.