Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // pinterest to be ONLY in right-click-menu to avoid button annoyance
- // manifest.json
- {
- "name": "Pinterest Menu ONLY Pin",
- "version": "1.0",
- "manifest_version": 2,
- "permissions": ["contextMenus"],
- "background": {
- "scripts": ["background.js"],
- "persistent": false
- }
- }
- // background.js
- chrome.runtime.onInstalled.addListener(function() {
- chrome.contextMenus.create({
- id: "saveToPinterest",
- title: "Save to Pinterest",
- contexts: ["image"]
- });
- });
- chrome.contextMenus.onClicked.addListener(function(info, tab) {
- if (info.menuItemId === "saveToPinterest" && info.srcUrl) {
- // Perform the action to save the image to Pinterest
- saveToPinterest(info.srcUrl);
- }
- });
- function saveToPinterest(imageUrl) {
- // Prepare the data to be sent to the Pinterest API
- const data = {
- image_url: imageUrl,
- // Add any additional parameters or data required by the Pinterest API
- };
- // Make a request to the Pinterest API to save the image
- fetch('https://api.pinterest.com/v1/pins/', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- // Include any required authentication or access token headers
- },
- body: JSON.stringify(data)
- })
- .then(response => {
- if (response.ok) {
- console.log('Image saved to Pinterest successfully!');
- // Handle any further actions or notifications on success
- } else {
- console.error('Failed to save image to Pinterest:', response.statusText);
- // Handle error cases and display appropriate messages
- }
- })
- .catch(error => {
- console.error('An error occurred while saving image to Pinterest:', error);
- // Handle any network errors or exceptions
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement