본문 바로가기
Computer/Chrome Extension

[Sample] Content Settings

by 생각하는달팽이 2015. 1. 30.

Content Settings


안녕하세요?

오늘은 크롬에서 보여지는 웹페이즈를 컨트롤 할 수 있는 기능을 따라해보겠습니다.




위의 샘플을 따라해보았습니다. 네이버의 이미지들이 표현되지 않도록 block 하고 진행하였습니다.


[ 컨텐츠 셋팅 SET ]


 chrome.contentSettings[type].set({

        'primaryPattern': pattern,

        'setting': setting,

        'scope': (incognito ? 'incognito_session_only' : 'regular')

      });


[ 컨텐츠 셋팅 GET ]


 chrome.contentSettings[type].get({

            'primaryUrl': url,

            'incognito': incognito

          },

          function(details) {

            document.getElementById(type).value = details.setting;

          });



  크롬 확장 API 의 사용은 위와 같이 한다.

Get  의 경우 아래와 같은 리스너에 등록해서 사용한다.


document.addEventListener('DOMContentLoaded', function () {

  chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {

...

});

...

});



Set 의 경우에는 function 에 작성한 후 html select tag 옵션의 listener에게 해당 함수를 위임한다.

그러면, 셀렉션 태그의 선택이 변할때마다 해당 함수가 호출되면서 컨텐츠의 셋팅 값을 변경한다.


그리고 변경된 값을 내부 컨텐츠들이 로드될때 적용시켜준다.



뭔가 컨텐츠 수정이라고 해서 이번 프로젝트에 사용할 것 같았으나..

컨텐츠자체를 수정하기는 하는데. 내가 생각했던 방향이 아니어서..

음.. 일단 이번 프로젝트에 안쓸것 같다.

반응형

'Computer > Chrome Extension' 카테고리의 다른 글

[Sample] Print this page  (0) 2015.01.30
[Sample] My Bookmarks  (0) 2015.01.30
크롬 확장 API 리스트 정리  (0) 2015.01.30
OverView  (0) 2015.01.28