Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
Can this simple Firefox extension be turned into a Greasemonkey script?

I have this Firefox extension that someone made for me. It prevents websites from opening download boxes and redirects and stuff like that. It works very well. It will prevent some websites from opening completely or working properly, but for my needs it works great.

Can this be turned into a Greasemonkey script, or it can only work as an extension?

main.js

    'use strict';

const mimeTypeMatch = function (header) {
  if (header.name === undefined) {
    return false;
  }
  if (header.name.toLowerCase() != 'content-type') {
    return false;
  }
  if (header.value.startsWith('image')) return false;
  if (header.value.startsWith('text')) return false;
  if (header.value.startsWith('font')) return false;
  if (header.value.startsWith('application/json')) return false;
  if (header.value.startsWith('application/javascript')) return false;

  console.log('cancel content type');
  console.log(header);
  return true;
};

const headersReceived = function (request) {
  return new Promise((resolve) => {
    let filter = false;

if ( (['somesite.com']).find( u => {
  const uri = new URL(request.originUrl);
  return u === uri.hostname;
}) ) {
  resolve({});
  return;
}

    request.responseHeaders.forEach(h => {
      if (mimeTypeMatch(h)) {
        filter = true;
        return;
      }
      if (h.name.toLowerCase() === 'content-disposition') {
        filter = true;
        return;
      }
    });

    if (filter) {
      resolve({
        cancel:true
      });
      return;
    }

    resolve();
  });
};

browser.webRequest.onHeadersReceived.addListener(
  headersReceived,
  {
    urls: ['<all_urls>']
  },
  [
    'blocking',
    'responseHeaders'
  ]
);

manifest.json

    {
  "manifest_version": 2,
  "name": "mime-type-cancel",
  "version": "1.0",
  "permissions": [
    "webRequest",
    "webRequestBlocking",
    "<all_urls>"
  ],
  "background": {
    "scripts": [
      "main.js"
    ]
  }
}

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The quick answer is, no.

Userscripts run in page context and they don't have access to Headers (e.g. request.responseHeaders) which happen before a page starts to load.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda