Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undisposition for chrome: toggle behaviour (active/not active) #1

Open
GianPaolo70 opened this issue Sep 7, 2017 · 6 comments
Open

Comments

@GianPaolo70
Copy link

I really like this extension, but I feel the need from time to time to disable it, and going through Chrome->Extension and so on is uncomfortable.

I wrote a few lines for toggling the extension with a click on the button, feel free to add them to your extension if you like.

undisposition_bg.js become

var active = true;
chrome.webRequest.onHeadersReceived.addListener(
	function(details){
	//console.log(details);
		var headers=details.responseHeaders;
		if (active)
		{
			for(var i=0;i<headers.length;i++){
				if(headers[i].name.toLowerCase()=='content-disposition'){
					if(headers[i].value.indexOf('attachment')==0){
						headers.splice(i,1);
						//headers[i].value='inline';
					}
					break;
				}
			}
			for(var j=0;j<headers.length;j++){
				if(headers[j].name.toLowerCase()=='content-type'){
					if(headers[j].value=='application/octet-stream'||headers[j].value=='application/x-download'){
						headers[j].value='text/plain'; //I hope Chrome is wise enough
					}
					break;
				}
			}
		}
		return {responseHeaders: headers};
	},
	{
		urls: ['<all_urls>'],
		types: ['main_frame','sub_frame']//,'stylesheet','script','image','object','xmlhttprequest','other']
	},
	['blocking', 'responseHeaders']
);

function loadOptions(callback)
{
	chrome.storage.local.get('activeStatus', function(data) {
		if (data.activeStatus === undefined) //at first install
		{
			data.activeStatus = true;
			saveOptions();
		}
		active = data.activeStatus;
		if (callback != null)
			callback();
	});
}

function saveOptions()
{
	chrome.storage.local.set({ activeStatus: active });
}

function updateUI()
{
	console.log("updateUI end, active = " + active);

	var str = active? "Undisposition active, click to deactivate": "Undisposition disabled, click to activate";
	chrome.browserAction.setTitle({title:str});
	chrome.browserAction.setBadgeText({text:active?"Act":"Dis"});
}

function ToggleActive()
{
	active = !active;
	saveOptions();
	updateUI();
}

loadOptions(updateUI);
chrome.browserAction.onClicked.addListener(ToggleActive);

in manifest.json, add browser_action and the permission for storage (in order to remember last status set)
e.g.

{
  "background": {
      "scripts": [ "undisposition_bg.js" ]
   },
   "description": "Remove Content-Disposition: attachment HTTP header.",
   "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDLBkZmL28J6RP1R8G5XutDFiaZyZqfvrmam8R6DMCrEeE7ncgF4r5tAWXMa7U/ulrfBV8IP9zvnNAt6smAVlugxBHTmUyYL1B7TUMaH2/WGNx0tlQWRMbNv3sWKcrhR/N1MdBCAfzkaSZ98NqPDCdoituwCkK275gLou8hTtG2UwIDAQAB",
   "manifest_version": 2,
   "name": "Undisposition",
   "permissions": [ "webRequest", "webRequestBlocking", "\u003Call_urls>", "storage" ],
   "update_url": "http://clients2.google.com/service/update2/crx",
   "version": "0.0.1",
   "browser_action": { } 
}

Right now I'm running my local (modified) copy of your extension, if you publish a version with the above feature I will surely install it.

I'm very noob with JS, if you find something orrible.... please let me know!

Thanks for your little and so precious extension
Gian Paolo

@Racle
Copy link

Racle commented Dec 27, 2019

@GianPaolo70 made fork and released this on Google web store if you still need it.

https://chrome.google.com/webstore/detail/undisposition-racle-fork/bbppejejjfancffmhncgkhjdaikdgagc

@GianPaolo70
Copy link
Author

GianPaolo70 commented Dec 30, 2019

That's great, installed. Thanks @Racle

@Racle
Copy link

Racle commented Jul 6, 2020

I'll share this in same thread. Some love for Firefox users also https://addons.mozilla.org/en-US/firefox/addon/undisposition-racle-fork/

@andyneff
Copy link

@Racle Is your fork open source?

@Racle
Copy link

Racle commented Aug 10, 2021

@Racle Is your fork open source?

I haven't released that to GitHub. It's basically code above with small tweaks so I just quickly modified and uploaded to Chrome/Firefox store.

Got no problem to get that on GitHub also (I'll do this when I'm at PC next time). You can also probably just unpack extension from official source and look that for your self. It's in plain text and has not been minimized :)

@Racle
Copy link

Racle commented Aug 11, 2021

@andyneff full source can be found here: https://github.com/Racle/undisposition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants