CoolFace
Apppublic

Elevatics/ai-web-scraper-backend

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
removeMedia.js57 linesDownload Raw Back to root
1// removeMedia.js
2function removeMedia($) {
3    try {
4      // Remove images
5      $('img').remove();
6      
7      // Remove video elements
8      $('video, source[type^="video"], object, embed').remove();
9      
10      // Remove audio elements
11      $('audio, source[type^="audio"]').remove();
12      
13      // Remove canvas elements
14      $('canvas').remove();
15      
16      // Remove SVG elements
17      $('svg').remove();
18      
19      // Remove picture elements
20      $('picture').remove();
21      
22      // Remove iframes
23      $('iframe').remove();
24      
25      // Remove media-specific attributes from elements
26      $('[poster]').removeAttr('poster');
27      $('[background]').removeAttr('background');
28      
29      // Remove inline media backgrounds
30      $('*[style*="background"]').each((_, el) => {
31        const $el = $(el);
32        const style = $el.attr('style');
33        if (style) {
34          const newStyle = style.replace(/background(-image)?:\s*url\([^)]+\);?/gi, '');
35          if (newStyle.trim()) {
36            $el.attr('style', newStyle);
37          } else {
38            $el.removeAttr('style');
39          }
40        }
41      });
42  
43      return {
44        success: true,
45        error: null
46      };
47    } catch (err) {
48      return {
49        success: false,
50        error: err.message
51      };
52    }
53  }
54  
55  module.exports = {
56    removeMedia
57  };