Advertisement
here2share

// pinterest to be ONLY in right-click-menu to avoid button annoyance

Nov 18th, 2023
744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // pinterest to be ONLY in right-click-menu to avoid button annoyance
  2.  
  3. // manifest.json
  4. {
  5.   "name": "Pinterest Menu ONLY Pin",
  6.   "version": "1.0",
  7.   "manifest_version": 2,
  8.   "permissions": ["contextMenus"],
  9.  
  10.   "background": {
  11.     "scripts": ["background.js"],
  12.     "persistent": false
  13.   }
  14. }
  15.  
  16. // background.js
  17. chrome.runtime.onInstalled.addListener(function() {
  18.   chrome.contextMenus.create({
  19.     id: "saveToPinterest",
  20.     title: "Save to Pinterest",
  21.     contexts: ["image"]
  22.   });
  23. });
  24.  
  25. chrome.contextMenus.onClicked.addListener(function(info, tab) {
  26.   if (info.menuItemId === "saveToPinterest" && info.srcUrl) {
  27.     // Perform the action to save the image to Pinterest
  28.     saveToPinterest(info.srcUrl);
  29.   }
  30. });
  31.  
  32. function saveToPinterest(imageUrl) {
  33.   // Prepare the data to be sent to the Pinterest API
  34.   const data = {
  35.     image_url: imageUrl,
  36.     // Add any additional parameters or data required by the Pinterest API
  37.   };
  38.  
  39.   // Make a request to the Pinterest API to save the image
  40.   fetch('https://api.pinterest.com/v1/pins/', {
  41.     method: 'POST',
  42.     headers: {
  43.       'Content-Type': 'application/json',
  44.       // Include any required authentication or access token headers
  45.     },
  46.     body: JSON.stringify(data)
  47.   })
  48.   .then(response => {
  49.     if (response.ok) {
  50.       console.log('Image saved to Pinterest successfully!');
  51.       // Handle any further actions or notifications on success
  52.     } else {
  53.       console.error('Failed to save image to Pinterest:', response.statusText);
  54.       // Handle error cases and display appropriate messages
  55.     }
  56.   })
  57.   .catch(error => {
  58.     console.error('An error occurred while saving image to Pinterest:', error);
  59.     // Handle any network errors or exceptions
  60.   });
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement