Re-Direct a page but not subdomain - google-chrome

I would like to be able to redirect a page to a subdomain using a chrome extension. After numerous attempts, nothing works.
Ideally, I want:
"https://www.facebook.com" -> "https://www.facebook.com/groups/123456789"
and "https://www.facebook.com/*" to be left alone (where * is a wild card).
To me it should be simple as there are no variables, but it doesn't appear to be. A further complication is that I started learning java yesterday, I am okay at html, c++, c, vb etc.
Why? Because I use facebook to keep up to date with solutions to problem sheets and things on my course, but my news feed is a) Distracting and b) rubbish.
If you can help you'd be a star (if you could comment your code that'd be awsome as I can learn a bit then as well) :D
So far I have, but it doesn't work :(
manifest.json
{
"name": "Tabber",
"manifest_version" : 2,
"version": "1.0",
"description": "MyExtension",
"chrome_url_overrides": {
"*www.facebook.com*": "my.html"
},
"permissions": [
"tabs"
]
}
my.html
<!DOCTYPE html>
<html>
<head>
<head>
<meta http-equiv="refresh"content="0;URL=http://www.google.com">
</head>
</head>
<body>
</body>
</html>

First, your mistakes.
chrome_url_overrides can only override bookmarks, history or newtab pages.
https://www.facebook.com/groups/123456789 is not a "subdomain"
It's JavaScript, not Java
Second, how to do it.
It's relatively easy to do with a content script. You don't need a tabs permission even, just the host permission for Facebook.
Manifest:
{
"name": "Tabber",
"manifest_version" : 2,
"version": "1.0",
"description": "MyExtension",
"content_scripts": [
{
matches: ["*://www.facebook.com/*"],
js: ["myscript.js"],
runAt: "document_start"
}
]
}
Then, your script will be injected when any tab navigates to any facebook page.
The script itself should check the URL and navigate away if needed:
// myscript.js
if(window.location.pathname == "/") {
window.location.replace("https://www.facebook.com/groups/123456789");
}
I don't use FB myself, so not sure if it will break any logic; but it's what you were trying to do.

Related

How do I enable only specific snippets in strings and why is my json snippet not working in json?

Ok, I am new to coding and just found out about costume snippets in VS-Code. I wrote some and they all worked pretty much as expected, but now I have some problems/questions. I have done some research but couldn't find any solutions.
1. how do I enable for example this snippet only in strings? Is there even a way? I don't want all my snippets to work in strings, just some.
"tab": {
"prefix": ["tab"],
"body": [
"${1|\\t,\\t\\t,\\t\\t\\t,\\t\\t\\t\\t,\\t\\t\\t\\t\\t,\\t\\t\\t\\t\\t\\t|}$0"
],
"description": "insert escaped tab"
},
adding this to the settings enables all snippets in strings which i don't want
"editor.quickSuggestions": {
"strings": true
},
2. I have written a snippet that should insert some lines into my launch.json file and it basically works the way I want, but only if I put the snippet in my global snippet file and not set the scope to json. It also does not work if I put it in the json snippet file (json.json). Why?
"launch json": {
// "scope": "json",
"prefix": "launch",
"body": [
"\"version\": \"0.2.0\",",
"\"configurations\": [",
"\t{",
"\t\t\"type\": \"${1|firefox,chrome|}\",",
"\t\t\"reAttach\": false,", // is there a way to auto remove this line if chrome is chosen
"\t\t\"request\": \"launch\",",
"\t\t\"name\": \"Launch index.html\",",
"\t\t\"file\": \"\\${workspaceFolder}/index.html\"",
"\t}",
"],",
"$0",
],
"description": "insert launch json"
},
that's the snippets output
"version": "0.2.0",
"configurations": [
{
"type": "firefox",
"reAttach": false,
"request": "launch",
"name": "Launch index.html",
"file": "${workspaceFolder}/index.html"
}
],
also is there a way to change the inserted lines depending on what option I chose from the list?
it's not really necessary, just wondering (the "reAttach": false, option only exists with firefox, so i don't need the line if i choose one of the other options)
3. Another problem I have is that I copied and then customized some already existing snippets (for java for example) and now it is showing both options in intellisense. I know, I know, I can press F1 -> insert snippet and click the eye symbol behind them to hide them from intellisense but that only works if the snippet actually is in the list, which isn't true for all of them. I just can't find some of them. Where can I find and disable them?
4. One last thing, I tried making a snippet for css with "prefix": ["*","somethingElse"], but i could not use the snippet with the * only the somethingElse worked, why is that? I already made two other snippets that use . and # as prefix and they also worked just fine. Is there something special about * when it comes to snippets?
I have no idea how to fix the main 4 problems or what causes them. But one way I thought about solving the optional line problem was something like this:
"\t\t\"type\": \"${1|firefox,chrome|}\",${2:\n\t\t\"reAttach\": false,}",
that way I can delete the line with one button if I don't need it. But the question was more about if it's possible in general so change some other lines depending on the option chosen from the list.

How does weava highlighter extension works under the hood?

There's weava highlighter extension which make it possible to highlights articles/pdf and store highlight on the server.
I can't understand how does it keep highlights after the page reloaded. What does need to be stored to find the highlighted section after the page reloaded? I can't store text, because text can be duplicated. CSS selectors not enough too, how does it work?
Tried to debug the extension, but the code is highly uglified and it's difficult to understand what's going on.
Actually, it stores enough text to describe the beginning and the end of the section to ensure uniqueness, found following traces in the console:
"-MI0L15LAX*************": {
"accessRight": {
"HZTU1cv32******************": "owner"
},
"createDate": 1600971612666,
"creator": "HZTU1cv32******************",
"favIconUrl": "https://cdn.sstatic.net/Sites/stackoverflow/Img/favicon.ico?v=ec617d715196",
"highlights": {
"d1311a13-d334-467c-8915-5faf412a689f": {
"colorNum": 3,
"creator": "HZTU1cv32p******************",
"date": 1600972075045,
"endStr": "afterthepagereloaded?ican'tsto",
"startStr": "tobestoredtofindthehighlighted",
"text": "section"
}
},
"title": "html - How does weava highlighter extension works under the hood? - Stack Overflow",
"url": "https://stackoverflow.com/questions/64052135/how-does-weava-highlighter-extension-works-under-the-hood",
"version": "0.0.3"
}
It isn't perfect, and error-prone (I was able to trick it to highlight the wrong section), but it looks that there's enough for most people.
Another drawback of such an approach, if the article changed a little bit (typo, etc...) the highlights can be lost.

how to add Facebook's pixel into Google's AMP?

For the time being, it appears that no one at Facebook nor Google have added Facebook tracking pixel into amp-analytics yet.
Does anybody here knows how to do it ? sample code or github is preferred.
thank you very much
This should work
<amp-pixel src="https://www.facebook.com/tr?id=YOUR_ID&ev=PageView&noscript=1"
layout="nodisplay"></amp-pixel>
You will need to change YOUR_ID to the ID you can find in Facebook's tracking code.
I created this by adopting the noscript src from their sample script for use in amp-pixel. More advanced usages would be possible, but ideally Facebook would provide the respective documentation.
It seems support was added on June 6, 2017. You can do:
<!-- Facebook Pixel Analytics tracking -->
<amp-analytics type="facebookpixel" id="facebook-pixel">
<script type="application/json">
{
"vars": {
"pixelId": "YOUR_ID"
},
"triggers": {
"trackPageview": {
"on": "visible",
"request": "pageview"
}
}
}
</script>
</amp-analytics>
<!-- End Facebook Pixel Analytics example -->
The documentation can be found here.

Showing ampersand in chrome context menu title

I have been working on a small Chrome extension with a problem: I can't seem to get my head around and would appreciate someone to look at it with a fresh perspective.
The goal is to create a Chrome extension which enables you to select text on any given website and display an option to send the selection to another website for search using a contextmenu item.
My manifest.json (v2) looks like this:
{
"name": "simple ext",
"version": "0.0.1.0",
"description": "this is a test",
"background": {
"scripts": ["js/test.js"]
},
"default_locale": "en",
"manifest_version": 2
}
messages.json:
{
"contextMenuTitle": {
"message": "Search for '$searchStr$'"
"placeholders":{
"searchStr": {
"content": "$1"
}
}
}
}
And js/test.js:
chrome.contextMenus.create({
"title": chrome.i18n.getMessage("contextMenuTitle", "%s"),
"contexts": ["selection"],
"onclick" : function(e){
if(e.selectionText){
var searchURL = getSearchURL(e.selectionText);
chrome.tabs.create({"url": searchURL});
}
}});
The problem I have is when I select text like "science & technology" the context menu shows the text "Search for 'science technology'" but in the onclick event, I get the correct text (that is 'science & technology'). So my searches work properly. The problem is with the text being shown as the title in the context menu.
I had a look at this and you might want to report a bug at http://crbug.com/ if one doesn't exist allready (had a 'quick' look and couldn't find anything). This 'bug' seems to apply to both the localization and context menu title. Neither will display an ampersand if you only use one, to get one to show for either it seems you have to use two && and then it will show as & (in your bug report, mention that this isnt explained in the docs either). But as you cant change the contents of %s before its shown I don't know how your going to deal with that....Unless you didn't use the %s and updated the title yourself every time they selected something on the page.
Perhaps its being rendered as html?
Try "Science & Technology"

Chrome extension to make a small CSS change to *.google.com

I just wrote a simple extension that has permission to *.google.com and changes some CSS on one class, and I think I overlooked something simple. I'm changing the +1 button, which is implemented like so:
<button ... class="esw eswd BRowJd Jt">
In my style.css I say:
button.eswa { border: 2px solid #000000; }
the change never appears. I also tried switching the class to Jt in case that was overriding my CSS, no luck. The class that defines the unclicked +1 button is the "eswa", fyi.
As per the documentation I also set permissions to the sites I want to alter in my manifest.json
{
"name": "G+ Rebrander",
"version": "0.92",
"description": "Returns the original branding for G+ (pre March 2012) such as the +1 button.",
"browser_action": {
"default_icon": "g-plus.png"
},
"icons":{
"128":"g-plus128.png"
},
"permissions": [
"http://plus.google.com/",
"https://plus.google.com/",
"http://*.google.com/",
"https://*.google.com/",
"tabs"
]
}
In the future listing your whole manifest.json file would be extremely helpful, since your didnt its hard for me to know exactly what your doing and thus what your error could be....so Ill just list a few possibilities.
Using !important in your css rule is always a good idea when overriding css.
Permissions is for if your injecting code from say the background page, not content scripts that get automatically added. The docs are slightly vague on that.
For content scripts that get added automatically you only need to set the matches field of the content script.
Your matches dont have a * at the end of them and as such would only match the front page and not any search results, which is what I assume your targeting.
Keep in mind that google will typically redirect to a server in your country, so for me going to www.google.com will be redirected to www.google.com.au.
The unlicked +1 for me was ewsd, not ewsa.
If your only injecting css and not a script aswell then its a good idea to use the run_at field with a value of document_start. This will make sure your css is applied before the page is visible and thus avoid the page changing later when it gets applied. If you use this then you must use !important or the css added by the page later will override your css rule.
So with all that a working manifest and css file looks like this.....
manifest.json
{
"name": "css rules",
"content_scripts": [
{
"matches": [
"*://*.google.com/*",
"*://*.google.com.au/*"
],
"css": ["new.css"],
"run_at" : "document_start"
}
],
"version":"1.0"
}
new.css
button.eswd { border: 2px solid #000000 !important;}
Set !important on the element to overwrite Google's style.