js/background.js
This is the file that's running when you click "background page" under Inspect Views.
When DEBUG
is set to true
in background.js
, many entries will be written to the JavaScript console, in the background, content, and overlays. Please be very careful not to ship with the debug flag on!
background.js
loads ctrl.json
locally in debug mode and from assets.pinterest.com
in production.
Local (debugging only): ctrl.json
Remote (production): https://assets.pinterest.com/ext/ctrl.json
Answers important questions like "should we use the iframed pin create experience," "should we allow unauthed search," and "should we turn off personalization from offsite browsing?"
Here's an example:
{
"ctrlVer": 2019010401,
"canHaz": {
"iframeSave": true,
"pfob": true
},
"search": {
"clientId": 1447278,
"authRequired": false,
"unauthPercent": 0
},
"endpoint": {
"about": "https://about.pinterest.com/",
"log": "https://log.pinterest.com/",
"grid": {
"pinCreate": "https://www.pinterest.com/pin/create/extension/",
"rePinCreate": "https://www.pinterest.com/pin/%s/repin/x/"
},
"save": "https://www.pinterest.com/browserbutton/create_pin/"
},
"path": {
"uninstall": "settings/extension/uninstall/",
"welcome": "browser-button-confirmation-page/"
},
"csrfDomain": "api.pinterest.com",
"wwwDomain": "www.pinterest.com"
}
When debugging API calls, set it to your-api.pinterdev.com
. When debugging WWW calls, you want to set it to you.pinterdev.com
.
Shows when canHaz.iframeSave
is not set in ctrl.json
html/create.html
calls js/create.js
Shows when canHaz.iframeSave
is set in ctrl.json
html/save.html
loads the file declared in endpoint.save
in ctrl.json
, currently https://www.pinterest.com/browserbutton/create_pin/
html/grid.html
calls js/grid.js
Our pinmarklet-rendering client.
html/search.html
calls js/search.js
Flashlight search for browser extensions.
html/options.html
calls js/options.js
js/content.js
Injects business logic and hash list on page load, and decides whether to run logic.js
.
Local: js/logic.js
Runs when content.js
says it's okay to do so. When working with this file, be extra careful not to load anything from our domain without user interaction. If you do the effect will be to track all of the user's traffic.
Remote: https://assets.pinterest.com/ext/hashList.json
Loads once on session start and is injected with business logic on every page load; helps to prevent hoverbuttons from showing on questionable domains.
Local: js/pinmarklet.js
Runs on click to browser button; loads html/grid.html
when complete.
Local: js/grid.js
Runs when called by user action on toolbar button. Pinmarklet should collect and forward data through the background process; in cases where there is only one pinnable thing, grid should close and save/create should open.
Local: js/save.js
Renders the iframe from pinterest.com when called by user action from hoverbutton, right-click, or grid save.
Local: js/create.js
Renders the onboard saving experience when called by user action from hoverbutton, right-click, or grid save.
Local: js/search.js
Runs when called by user action via right-click, hoverbutton, or click to Search button in grid.
js/options.js
Saves user preferences (currently: hide hoverbuttons)
_locales/*/messages.json
One file for each supported language. If you change anything in here, be sure to budget time for translation services!
Translated messages were removed from business logic with version 4.0.74 and improved with 4.0.75; on session start the background process should load all messages in the correct language using the i18n API and move them into local storage. Business logic reads local storage on load, so messages should be immediately available.
If you add messages that need to show in overlays, you will want to add them to the translateThese object in background.js in the appropriate overlay sub-object.
Pinmarklet is the sole holdout where messages are still in code, because it runs on many clients outside browser extensions.
img/*.png
img/disabled/*.png
Icons and chrome buttons; those in the disabled
folder are grayed-out versions for the toolbar button.
manifest.json
Be careful about permissions changes; if you request permissions not already required by the extension, the extension will be disabled until the user grants the new permissions. For us the scope is already pretty scary; expect users to balk and uninstall rather than update.
Special note about Firefox: it wants the <all_urls>
permission in order to make screenshots. Chrome should not need this permission.
readme.md
You're reading it now. Please help keep it up to date!
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。